-
Notifications
You must be signed in to change notification settings - Fork 30k
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
No event on child-process stdout #2926
Comments
|
That is the solution for me, thank you! Since I don't intend to use
And for a small set of programs I tried it on, output arrives at each newline. |
For me, I had set an environment variable in the spawn(command, {
env: {
BROWSER: "none"
}
} In Windows, other environment variables seemed to be carried along. But in WSL, they were not, so the program was not working. The solution was to spread the other environment variables such as: spawn(command, {
env: {
...process.env,
BROWSER: "none"
}
} which worked in both Windows and WSL envs. |
I'd like to have a nodejs script interact with a child process via standard input and output. I've tried setting this up with what the documentation provides, but I've arrived at a deadlock where what's happening doesn't match what's I believe is documented.
What I see in the documentation:
Reading each section leads me to:
The section for spawn describes access to an
stdio
option. Looking further up the page, I read that the child's stdin and stdout both default to a writeable or readable stream.OK, I don't entirely know what a stream is in the context of Node, so looking at the stream doc page:
Cool, and then since I've already looked at the child-process.spawn examples, I know that
.on('data'...
is important. It's listed right below:This looks pretty straightforward, I want
spawn
. This child process of mine will persist for a while, and I want access to the output as it appears. Sounds like a good match.Running the provided example:
Great, time to become familiar with the
.spawn
operator. To do so, I'll run the providedps ax | grep ssh
example:Output:
It works!
Running a modified example:
But I notice that grep exits pretty quickly. I want my program to persist, so I'm going to modify the example to leave grep running for a while longer.
Output:
No output? Why would that be the case? Closing grep's stdin will cause it to exit, leaving it open keeps me from seeing the output I want. All in all, how is this different from the functionality of
.exec
?I tried to link pretty closely to the documentation because I'm confident that Node is working as expected and that I've misread something that brought me here.
The text was updated successfully, but these errors were encountered: