-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
exec() behaves differently across platforms (was "Child process should handle exit status >128 like exit status <0") #4432
Comments
So, it seems like this is a bug (or lack of feature?) in /bin/sh, which perhaps Node can't/shouldn't work around.
So, it looks like I'm honestly not sure the best fix here (including the default of just shrugging and documenting it). This is a weird source of platform incompatibility stemming from the fact that |
More investigation: turns out that this linux system is an Ubuntu system, where However, running this test with dash on OS X yields the same results as bash. I'm a bit lost, and tempted to just shrug and not worry about catching signal exits on |
Test case showing this is a /bin/dash weirdness, and probably Node is doing the right thing: var spawn = require('child_process').spawn
var exe = '/bin/sh' // replace with /bin/bash or /bin/dash to test
var sh = spawn(exe, ['-c', exe + ' -c \'kill -15 $$\''])
sh.on('exit', function (code, signal) {
console.error(code, signal)
}) |
@isaacs check out AndreasMadsen/execspawn#2. Would love to get this use case working. Does replacing |
if so, could also be the culprit here.. #2098 |
Relying on existence of I usually check for either Also, there are further weirdnesses unrelated to the shell, but related to node signal emulation. If you use And various versions of node, depending on whether stdio has been used :-(, will possibly internally catch signals, to reset the tty state, then exit with Its a bit of a mine field. |
Feel free to comment or re-open if you think I'm mistaken, but I'm going to close this seeing as:
All that said, I don't feel strongly about it, so feel free to re-open. (I'm just going through old issues and closing ones that don't seem actionable based on what I understand.) |
On linux systems (perhaps anything with a "real" /bin/sh which is not an alias to /bin/bash?) signal exits are reported with a high exit status, rather than a negative number.
I'm not sure if this is a discrepancy that should be handled in libuv, or somewhere else, but this test shows the difference between running a child process with sh vs running with bash, and then killing the process with a SIGTERM signal.
The bash child process exits with a properly communicated signal, but the sh process has a weirdly large exit code when a negative exit code is expected (indicating a signal exit).
If this isn't something that Node can or should address, then I think that a caveat in the child_process.exec documentation is worth adding.
Expected output (as seen on darwin, where sh is bash)
Actual output (on linux, where sh is sh)
The text was updated successfully, but these errors were encountered: