【发布时间】:2019-07-13 08:03:24
【问题描述】:
我在 index.js 中有以下代码:
var child = exec(
'node app.js --board=' + data.data.board + ' --link=' + data.data.link,
function (error, stdout, stderr) {
if (error) console.log('exec error: ' + error)
if (stderr) console.log('stderr: ' + stderr)
}
)
.stdout.on('data', function(log_data) {
console.log(log_data)
socket.emit('listener', { ty: 'user_p_logs', num: data.num, log: log_data })
fn(true)
})
这是run app.js 的代码,但我无法在index.js 上停止这个子进程
我在index.js中尝试了以下操作:
child.kill()
child.kill('SIGINT')
process.exit() // This stopped index.js, instead of its child.
更新:有答案吗?
【问题讨论】:
-
你需要将进程分配给
child,这样你才能杀死它。 -
我该怎么做?
标签: javascript node.js exec child-process