执行exe nodejs,完成时标记

时间:2016-10-18 11:45:41

标签: javascript node.js shell client

我从我的服务器上运行了一个exe文件,如下所示:

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

               runTest();

           });
}

一切正常,我可以在控制台中看到所有运行的东西。

但是我想在exe完成后想要一个标志,所以我可以提醒客户说运行是成功的。

想要在exe和parse中添加“已成功完成”行 它。可以这样做吗?

由于

1 个答案:

答案 0 :(得分:1)

侦听close和error事件以获得有关执行结束的通知:

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.');
});
相关问题