{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/node-pty/issues/190","repository_url":"https://api.github.com/repos/Microsoft/node-pty","labels_url":"https://api.github.com/repos/Microsoft/node-pty/issues/190/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/node-pty/issues/190/comments","events_url":"https://api.github.com/repos/Microsoft/node-pty/issues/190/events","html_url":"https://github.com/Microsoft/node-pty/issues/190","id":319110902,"number":190,"title":"`process.on('exit')` is disabled after `spawn` a child process.","user":{"login":"zhaoyi0113","id":3355579,"avatar_url":"https://avatars0.githubusercontent.com/u/3355579?v=4","gravatar_id":"","url":"https://api.github.com/users/zhaoyi0113","html_url":"https://github.com/zhaoyi0113","followers_url":"https://api.github.com/users/zhaoyi0113/followers","following_url":"https://api.github.com/users/zhaoyi0113/following{/other_user}","gists_url":"https://api.github.com/users/zhaoyi0113/gists{/gist_id}","starred_url":"https://api.github.com/users/zhaoyi0113/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhaoyi0113/subscriptions","organizations_url":"https://api.github.com/users/zhaoyi0113/orgs","repos_url":"https://api.github.com/users/zhaoyi0113/repos","events_url":"https://api.github.com/users/zhaoyi0113/events{/privacy}","received_events_url":"https://api.github.com/users/zhaoyi0113/received_events","type":"User","site_admin":false},"labels":[{"id":563204273,"url":"https://api.github.com/repos/Microsoft/node-pty/labels/need%20more%20info","name":"need more info","color":"e6e6e6","default":false},{"id":379882446,"url":"https://api.github.com/repos/Microsoft/node-pty/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2018-05-01T04:15:56Z","updated_at":"2018-05-15T14:59:25Z","closed_at":"2018-05-07T00:11:02Z","author_association":"NONE","body":"I am using `node-pty` to spawn a child process as below:\r\n\r\n```\r\nconst { spawn } = require('node-pty');\r\n\r\nconst handleShutdown = (e, n) => {\r\n  console.log('exit', e, n);\r\n  process.exit(e);\r\n};\r\nprocess.on('exit', handleShutdown);\r\nprocess.on('SIGINT', handleShutdown);\r\nconst p = spawn('mongo', ['mongodb://localhost:27017/admin']);\r\n\r\n```\r\n\r\nwhen I terminate the node process, the `handleShutdown` is not being called. But if I move the `process.on` after `spawn`, the `handleShutdown` is called on termination. I think the `spawn` override process listeners for some reasons. How can I fix that?"},"comment":{"url":"https://api.github.com/repos/Microsoft/node-pty/issues/comments/389198855","html_url":"https://github.com/Microsoft/node-pty/issues/190#issuecomment-389198855","issue_url":"https://api.github.com/repos/Microsoft/node-pty/issues/190","id":389198855,"user":{"login":"Tyriar","id":2193314,"avatar_url":"https://avatars0.githubusercontent.com/u/2193314?v=4","gravatar_id":"","url":"https://api.github.com/users/Tyriar","html_url":"https://github.com/Tyriar","followers_url":"https://api.github.com/users/Tyriar/followers","following_url":"https://api.github.com/users/Tyriar/following{/other_user}","gists_url":"https://api.github.com/users/Tyriar/gists{/gist_id}","starred_url":"https://api.github.com/users/Tyriar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tyriar/subscriptions","organizations_url":"https://api.github.com/users/Tyriar/orgs","repos_url":"https://api.github.com/users/Tyriar/repos","events_url":"https://api.github.com/users/Tyriar/events{/privacy}","received_events_url":"https://api.github.com/users/Tyriar/received_events","type":"User","site_admin":false},"created_at":"2018-05-15T14:59:25Z","updated_at":"2018-05-15T14:59:25Z","author_association":"MEMBER","body":"I run this piece of code and it exits correctly on Linux?\r\n\r\n```js\r\nvar os = require('os');\r\nvar pty = require('node-pty');\r\n\r\nvar shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';\r\n\r\nvar ptyProcess = pty.spawn(shell, [], {\r\n  name: 'xterm-color',\r\n  cols: 80,\r\n  rows: 30,\r\n  cwd: process.env.HOME,\r\n  env: process.env\r\n});\r\n\r\nptyProcess.on('data', function(data) {\r\n  console.log(data);\r\n});\r\n\r\nptyProcess.write('ls\\r');\r\nptyProcess.write('exit\\r');\r\nprocess.on('exit', c => console.log('exit ' + c));\r\n```"}}
{"actor":{"display_login":"Tyriar"}}