Mumfordwiz Mumfordwiz - 1 year ago 98
Node.js Question

execute exe nodejs, flag on completion

I got an exe file i'm running from my server, like so:

var spawn = require('child_process').spawn;
var testing= spawn('testing.exe');
if (data.type === "start") {
testing.stdout.on('data', function (data) {



it all works and I can see in the console everything that runs.

However I would like a flag after the exe has completed so i can alert the client that the run was a success.

I don't want to add the line "completed successfully" in the exe and parse
it. Can this be done?


Answer Source

Listen for close and error events to get notified about the end of execution:

testing.on('close', function(code) {
  if (code !== 0) {
    console.log(`Child process exited with code ${code}`);
  } else {
    console.log('Child process completed successfully');

testing.on('error', function(err){
  console.log('Child process failed.');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download