【发布时间】:2018-05-01 06:39:36
【问题描述】:
我正在尝试使用 spawn 进程运行 c++ 可执行文件。这是可执行文件的 c++ 代码:
#include<iostream>
#include<string>
using namespace std;
void divide(int num1, int num2) {
// Complete this function
cout << num1/num2;
}
int main(){
int num1, num2;
cin >> num1 >> num2;
divide(num1, num2);
return 0;
}
这是nodejs的代码
var bat = spawn(filePath);
bat.stdin.write("6\n");
bat.stdin.write("0\n");
bat.stdout.on('data', function (data) {
console.log("Output: ", data.toString());
});
bat.stderr.on('data', function (data) {
console.log("Error: ", data.toString());
});
bat.once('exit', function (code) {
console.log('Child exited with code ' + code);
return;
});
我无法使用此代码捕获“除以零”异常。这段代码缺少什么?任何帮助将不胜感激。
【问题讨论】:
标签: javascript node.js exception-handling spawn