我正在使用 child_process.spawn
运行 gulp
命令,并尝试从 gulp 发送消息。到目前为止我做到了
gulpfile.js
gulp.task('default', gulp.series(
done => {
process.send({message: 'finished'})
done()
}
))
index.js
proc = spawn(path.resolve(__dirname, '../node_modules/.bin/gulp'), ['--gulpfile', gulpFilePath], {
cwd: data.projectPath,
env: process.env,
silent: true,
})
proc.on('message', msg => {
console.log(msg)
})
但我没有收到消息。
有办法做到这一点吗?
最佳答案
我应该能够通过将 option.stdio 设置为 [ 'pipe', 'pipe', 'pipe', 'ipc' ] 来发送消息
关于javascript - 有没有办法在 child_process.spawn 和父进程之间进行通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50092894/