Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use spawn instead of exec to execute command (Fixes #171) #428

Merged
merged 2 commits into from
Aug 14, 2019
Merged

Use spawn instead of exec to execute command (Fixes #171) #428

merged 2 commits into from
Aug 14, 2019

Conversation

JeffreyCA
Copy link
Contributor

@JeffreyCA JeffreyCA commented Feb 8, 2019

Fixes #171

The following Python code now runs to completion without having to set runInTerminal to true.

for count in range(100000):
    print(count)

When using spawn, the stdout and stderr data object is a uint8array so it needs to be decoded into a string before appending to the output channel.


this._process.stdout.on("data", (data) => {
this._outputChannel.append(data);
this._outputChannel.append(decoder.decode(data));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between decoder.decode(data) and data.toString()? Others look good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling toString() on data (a uint8array) results in a string representation of the int array, not the actual decoded value.

Also see this

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the official doc also use data.toString() :https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
And I have tried data.toString(), the output is the same decoder.decode(data). Just want to know if there is any case needed to use decoder.decode(data), since data.toString() would be simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this was a couple of months ago so I don't remember exactly why I used TextDecoder. I have made the change.

@formulahendry formulahendry merged commit 7548e15 into formulahendry:master Aug 14, 2019
@formulahendry
Copy link
Owner

Thanks @JeffreyCA !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incomplete output displayed and [Done] exited with code=null
2 participants