{"action":"created","issue":{"url":"https://api.github.com/repos/Tyriar/node-pty/issues/188","repository_url":"https://api.github.com/repos/Tyriar/node-pty","labels_url":"https://api.github.com/repos/Tyriar/node-pty/issues/188/labels{/name}","comments_url":"https://api.github.com/repos/Tyriar/node-pty/issues/188/comments","events_url":"https://api.github.com/repos/Tyriar/node-pty/issues/188/events","html_url":"https://github.com/Tyriar/node-pty/issues/188","id":316215399,"number":188,"title":"[Question] How to capture session task exit code","user":{"login":"noyobo","id":1292082,"avatar_url":"https://avatars1.githubusercontent.com/u/1292082?v=4","gravatar_id":"","url":"https://api.github.com/users/noyobo","html_url":"https://github.com/noyobo","followers_url":"https://api.github.com/users/noyobo/followers","following_url":"https://api.github.com/users/noyobo/following{/other_user}","gists_url":"https://api.github.com/users/noyobo/gists{/gist_id}","starred_url":"https://api.github.com/users/noyobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noyobo/subscriptions","organizations_url":"https://api.github.com/users/noyobo/orgs","repos_url":"https://api.github.com/users/noyobo/repos","events_url":"https://api.github.com/users/noyobo/events{/privacy}","received_events_url":"https://api.github.com/users/noyobo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-20T10:31:54Z","updated_at":"2018-04-20T10:39:12Z","closed_at":null,"author_association":"NONE","body":"```js\r\n// foo.js\r\nprocess.exit(123);\r\n```\r\n\r\n```js\r\nvar os = require('os');\r\nvar pty = require('node-pty');\r\nvar Terminal = require('xterm').Terminal;\r\n\r\n// Initialize node-pty with an appropriate shell\r\nconst shell = process.env[os.platform() === 'win32' ? 'COMSPEC' : 'SHELL'];\r\nconst ptyProcess = pty.spawn(shell, [], {\r\n  name: 'xterm-color',\r\n  cols: 80,\r\n  rows: 30,\r\n  cwd: process.cwd(),\r\n  env: process.env\r\n});\r\n\r\n// Initialize xterm.js and attach it to the DOM\r\nconst xterm = new Terminal();\r\nxterm.open(document.getElementById('xterm'));\r\n\r\n// Setup communication between xterm.js and node-pty\r\nxterm.on('data', (data) => {\r\n  ptyProcess.write(data);\r\n});\r\nptyProcess.on('data', function (data) {\r\n  xterm.write(data);\r\n});\r\n\r\nptyProcess.write('node foo.js\\n');\r\n```\r\n\r\nHow to capture the exit code `123` of the session task?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Tyriar/node-pty/issues/comments/383057615","html_url":"https://github.com/Tyriar/node-pty/issues/188#issuecomment-383057615","issue_url":"https://api.github.com/repos/Tyriar/node-pty/issues/188","id":383057615,"user":{"login":"mofux","id":2785983,"avatar_url":"https://avatars1.githubusercontent.com/u/2785983?v=4","gravatar_id":"","url":"https://api.github.com/users/mofux","html_url":"https://github.com/mofux","followers_url":"https://api.github.com/users/mofux/followers","following_url":"https://api.github.com/users/mofux/following{/other_user}","gists_url":"https://api.github.com/users/mofux/gists{/gist_id}","starred_url":"https://api.github.com/users/mofux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mofux/subscriptions","organizations_url":"https://api.github.com/users/mofux/orgs","repos_url":"https://api.github.com/users/mofux/repos","events_url":"https://api.github.com/users/mofux/events{/privacy}","received_events_url":"https://api.github.com/users/mofux/received_events","type":"User","site_admin":false},"created_at":"2018-04-20T10:39:12Z","updated_at":"2018-04-20T10:39:12Z","author_association":"NONE","body":"node-pty starts your shell process, but any process spawned within that shell process (like `node foo.js`) is outside of the knowledge of node-pty. It doesn't track sub-processes or exit codes of those.  What you could do is spawning the `node foo.js` directly, e.g.:\r\n\r\n```javascript\r\nconst ptyProcess =  pty.spawn('node', ['foo.js'], {...});\r\nptyProcess.on('exit', (code, signal) => {\r\n  // should log 123\r\n  console.log(code); \r\n});\r\n```"}}
{"actor":{"display_login":"mofux"}}