-
Notifications
You must be signed in to change notification settings - Fork 211
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
Add support for .on('exit', ...) returning process exit status #110
Conversation
Any updates on this? Would be awesome to have merged. |
@chjj We need the exit code that this PR implements to make the Cloud9 installer function properly. Would you have time to take a look? Thanks! |
I would be interested into this as well. |
Is there anyway we can get some traction on this? I would be willing to fix this with some guidance on what is the best way to do it. Looking at the issues, there are a couple of ways to go about it. @chjj any thought? |
Sorry, this one flew totally under the radar for me. This handles SIGCHLD via libuv functions? Am I seeing that right? That's exactly what we needed if that's the case. Calling |
Merging this for now. If this handles SIGCHLD the libuv way and fixes the zombie process issue, I'm all for it. This was the problem I had: binding to SIGCHLD the traditional way caused issues with libuv. |
Add support for .on('exit', ...) returning process exit status
I'm getting a segfault on pty exit. node v0.12.7 |
That last commit seemed to fix it. |
Sorry, the commit above this comment ^ |
The next step is to figure out how compatible this is with previous node/libuv versions. |
Is it possible to issue a release which includes this? Thank you. |
@amshali, yes, but I want to test it on multiple OSes and node versions first. Give it a day or two. |
Also, feel free to test on whatever platform you're using and let us know. |
So far works on node v0.12.x on Arch Linux and OSX. |
Getting some bizarre side effects on v0.12.5 (Linux), but v0.12.7 seems fine. |
I take it back. v0.12.5 seems fine now. |
Build error on v0.10.7 (Linux):
Looks like the uv api changed a bit between versions. We can account for that I suppose. |
Added a version check to fix the arguments for past versions of uv_async_init. |
Fixed node v0.10.7. Node v0.8.21 also works. |
pty.js v0.2.9 published, complete with exit codes and no zombies. |
Thanks a bunch!!! :) |
Thank you. Can't wait to test it. Would you mind posting a minimal test case, then I could test it on FreeBSD and OS X El Captain.
|
@tobiastom, here's a simple test for now that you can copy and paste to see the exit status: var pty = require('pty.js');
var term = pty.spawn('sleep', ['3'], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});
term.on('exit', function(code) {
console.error('CODE: ' + code);
}); OR: var pty = require('pty.js');
var term = pty.spawn('bash', ['-c', 'echo 1; sleep 3; echo 2; exit 1'], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});
term.on('data', function(data) {
process.stderr.write(data);
});
term.on('exit', function(code) {
console.error('CODE: ' + code);
}); |
@chjj Works great for me on:
Thanks again for adding this functionality! |
Remember to thank @joshwilsdon: he figured out a way to do this without overriding node's SIGCHLD handler, which was a huge issue in the first place. |
Oh, I missed that the pull request originated from him. Thanks @joshwilsdon. You made my day. :) |
Fixed a few issues:
|
It would be wise to test these fixes on all platforms and versions again. |
Also, it looks like in node v0.8.x, waitpid is already handled somewhere else. errno is ECHILD. I've accounted for this, and everything will work, but node v0.8.x will always get an exit status of 0. |
pty.js v0.2.10 published. Please test. |
@chjj 0.2.11 seems to work on all my tested platforms from above. |
@tobiastom, good news. And I have another small improvement for this I'm going to publish tonight. It looks like every platform from node v0.8.x onward should work at least. |
* add support for .on('exit', function (code, signal) {}) * use an arg instead of arguments[0] * htop command cannot resize with env.LINSE and env.COLUMNS * v0.2.8. fixes chjj#122. * style conventions. * fix build. see chjj#110. * call uv_close to take cb off the event loop. see chjj#110. * more style fixes. * use older v8 api for function casts? * fix after_wait_on_pid for node v0.10.x. see chjj#110. * fix close events. see chjj#110. * v0.2.9 * refactor waitpid thread. * refactor pty.fork args. * free up baton in uv_close callback. see chjj#110. * fix issue where exit is emitted before the last data event. see chjj#110. * account for node v0.8.x on waitpid. see chjj#110. * v0.2.10 * add comment. * v0.2.11 * better onexit callback. * event better onexit callback. see chjj#110. * v0.2.12 * create scope in pty_after_waitpid to prevent fatal v8 error in io.js. fixes chjj#126. * v0.2.13 * upgrade to nan 2.0.5. see chjj#127. * remove "heap-style" Nan::Callback. * strict nan version. * remove useless v8 namespace prefixes. * minor: whitespace. cols. * bind to close only once. * v0.3.0 * update win/pty.cc to work with nan 2.0.5 * Optional resuming of the socket The immediate resumption the a socket means that output can be lost unless you start consuming it right away. In some cases, this behavior is undesirable. Adding an option to not automatically resume the socket enables data to be read after a delay. * Update nan version
* add support for .on('exit', function (code, signal) {}) * use an arg instead of arguments[0] * htop command cannot resize with env.LINSE and env.COLUMNS * v0.2.8. fixes chjj#122. * style conventions. * fix build. see chjj#110. * call uv_close to take cb off the event loop. see chjj#110. * more style fixes. * use older v8 api for function casts? * fix after_wait_on_pid for node v0.10.x. see chjj#110. * fix close events. see chjj#110. * v0.2.9 * refactor waitpid thread. * refactor pty.fork args. * free up baton in uv_close callback. see chjj#110. * fix issue where exit is emitted before the last data event. see chjj#110. * account for node v0.8.x on waitpid. see chjj#110. * v0.2.10 * add comment. * v0.2.11 * better onexit callback. * event better onexit callback. see chjj#110. * v0.2.12 * create scope in pty_after_waitpid to prevent fatal v8 error in io.js. fixes chjj#126. * v0.2.13 * upgrade to nan 2.0.5. see chjj#127. * remove "heap-style" Nan::Callback. * strict nan version. * remove useless v8 namespace prefixes. * minor: whitespace. cols. * bind to close only once. * v0.3.0 * update win/pty.cc to work with nan 2.0.5 * Optional resuming of the socket The immediate resumption the a socket means that output can be lost unless you start consuming it right away. In some cases, this behavior is undesirable. Adding an option to not automatically resume the socket enables data to be read after a delay. * update dependency nan@2.0.5 to nan@2.3.3 * update nan to @2.3.5 * v0.3.1 * pty.kill is not a function see https://codio.myjetbrains.com/youtrack/issue/codio-9306 * add comment
In order to have the shell pass the exit code through to the
|
This should resolve #28 and adds the ability to get the exit code and signal (if killed by signal) when a pty spawned process exits.