-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
When executable is spawned from node if there is no stdin getStdin() never resolves #13
Comments
That's expected. Since you've executed |
But I'm not writing to stdin in the first example from the shell and it doesn't hang. It's only when it's spawned from node via Is there a way I can simulate the first example from exec so I can test for help output in AVA? |
That's because in the first example the process is interactive, in the second, it's spawned, so it's not.
Write to stdin, or make the process interactive. The only way to make it interactive as far as I know is to |
The thing is if I write to stdin it'll work with that data and won't show the help output 😢 I'll look in to making the process interactive, thanks for the explanation 👍 |
Without knowing exactly how
I'm assuming that's what's going on here: spawning a new process in Node has a high potential to munge the I/O descriptors of the child process (either turning them off or piping to them instead of forwarding them or marking them as interactive). If you're not Since we can only "best guess" as to what's going on, we assume there is data going to be piped in. Hopefully that helps. |
@Qix- Lines 15 to 25 in e89bea4
|
@Qix- My question is. Why does stdin need to block? It's very annoying that you can't both have an stdin listener and write to stdout, without anything coming into stdin. |
You can; could you explain exactly what you mean? Writing to stdout while reading stdin is perfectly possible - at least, on the unix side of things. Not sure if listening in Node blocks stdout, but that definitely shouldn't be the case. |
Just tried and it works fine: lukechilds@545a9fc want a PR? AVA tests pass but the |
For this module, we only really care about stdin that is written right away, like when the process is piped. This has the benefit of letting us easily add a fallback when there's no stdin. Fixes #13
encountered same problem when using https://github.com/silverwind/oui which use get-stdin but hang there if the stdin is not closed by parent process. |
It seems that all async spawn methods need to explicitely close var exec = require('child_process').exec;
var child = exec('node dist/cli.js');
child.stdout.pipe(process.stdout);
child.stdin.end(); Ongoing discussion in: nodejs/node#2339 (comment) |
Re @ulion: yep, that's right; there's no way for a process to know when stdin is finished until the pipe itself is closed. |
@silverwind Thanks so much, have a gold star! 🌟 All working now: lukechilds/htconvert@a8f0476 |
If there is no file option set my CLI app falls back to
getStdin()
.I check if the result of the file read or
getStdin()
is falsey and if so I show the help message.This works fine when used for real in a shell but when I try to write a test for it, it just hangs. It seems if I spawn my CLI app from node,
get-stdin()
returns a promise that never resolves. For example:But if I run this from node:
I get nothing.
Not sure if possibly related to #1. Is this expected behaviour or a bug?
The text was updated successfully, but these errors were encountered: