After running terminal.sendtext("some command")
, how do I get the exit code of the command? If this is not possible, is there a way to run the command in external terminal(using something likechild_process.spawnSync()
) and get the exit code?
Asked
Active
Viewed 1,002 times
3

Aleksey L.
- 35,047
- 10
- 74
- 84

Agile_Eagle
- 1,710
- 3
- 13
- 32
-
Maybe this helps https://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line – Ehsan Kiani Apr 26 '20 at 06:03
-
1@EhsanKiani But how can I get that from integrated terminal in an extension? – Agile_Eagle Apr 26 '20 at 06:16
-
I will search and get back to you if I found something useful. – Ehsan Kiani Apr 26 '20 at 06:21
2 Answers
0
You could do something like this
const { spawn } = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process close all stdio with code ${code}`);
});
ls.on('exit', (code) => {
console.log(`child process exited with code ${code}`);
});
Reference : https://nodejs.org/dist/latest-v12.x/docs/api/child_process.html#child_process_event_close

Ashutosh Kumar
- 11
- 1
0
You could use the new terminal exit api, see v1.71 Release Notes: terminal exit status api:
TerminalExitStatus.reason
Extension authors now have better insight into why a terminal exited via the new TerminalExitReason API.
export enum TerminalExitReason {
Unknown = 0,
Shutdown = 1,
Process = 2,
User = 3,
Extension = 4,
}

Mark
- 143,421
- 24
- 428
- 436