2

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

1 Answers1

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