3

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?

Aleksey L.
  • 35,047
  • 10
  • 74
  • 84
Agile_Eagle
  • 1,710
  • 3
  • 13
  • 32

2 Answers2

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

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