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 502 times
2
Aleksey L.
- 30,955
- 9
- 62
- 73
Agile_Eagle
- 1,572
- 2
- 12
- 27
-
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
1 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