问题描述
我使用spawn函数在execFile的回调函数中运行child_process。
但是我无法从spawn函数获得结果。
下面我写我的代码。
const execChild = require('child_process').execFile;
const execSpawn = require('child_process').spawn;
let childprocess=0
module.exports.getresult= function()
{
execChild('1.exe',[
...arguments....
],function(err,data){
try{
childprocess= execSpawn('2.exe',[
...arguments....
])
childprocess.stderr.on('data',(data) => {//function1
console.error(`stderr: ${data}`);
});
childprocess.stdout.on('data',(data) => {//function2
console.error(`stdout: ${data}`);
});
childprocess.on('close',(code) => {//function3
console.log(`child process exited with code ${code}`);
});
childprocess.on('error',function (err) {//function4
console.log(err)
console.log('Failed to start child process.');
});
childprocess.on('exit',(code) => {//function5
console.log(`exit ${code}`);
});
}catch(err){
console.log('BIGERR')
}
})
}
我让5个事件接收器从childProcess接收结果。
但是我无法从childProcess中得到任何结果。
如何从子进程中获取结果。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)