【发布时间】:2015-09-15 19:59:56
【问题描述】:
我的目的只是使用 node.js 启动一个 exe。如果应用程序意外终止,则应捕获异常并将其记录在协议中。在 c++ 项目中通过以下语句引发异常:
throw std::string("NOT X or x!!!");
我的 Javascript 是:
var spawn = require('child_process').spawn;
var cp = spawn(process.env.comspec, ['/c', 'myExcepTest.exe', '', '']);
// **doesn't work**
cp.on('uncaughtException', function(err){
console.log("Caught exception: " + err);
});
cp.stderr.on('error', function(err) {
console.log(err.toString());
});
cp.stdin.resume();
cp.stdin.setEncoding('utf8');
cp.stdin.on('data', function(data) {
cp.stdout.write(data);
});
// **does work**
cp.on('exit', function(code){
console.log("Child exited with code: " + code);
});
cp.stdout.on('data', function(data) {
console.log(data.toString());
});
我的问题是:
使用 node.js 监控进程是否是一个好习惯 视窗?
是否可以使用 node.js 捕获异常 视窗?
如何在 node.js 中正确地将标准输入通过管道传输到标准输出 脚本?
对不起我的英语不好;)
【问题讨论】:
标签: c++ node.js windows exception performance-testing