1
當我通過一個npm腳本產生一個子進程時,我失去了ipc通道。當通過npm腳本產生一條消息從子進程到父進程
我有這樣
if (process.send) { process.send('child') }
孩子腳本,如果產卵它像這樣另一個腳本,父進程將成功接收並打印消息
var spawn = require('child_process').spawn
spawn('node', ['child.js'], {stdio: ['inherit', 'inherit', 'inherit', 'ipc'})
spawn.on('message', function (msg) { console.log(msg) })
但是如果我定義node child.js
爲我的package.json中的一個npm腳本,如
"scripts": {
"child": "node child.js"
}
an d代替spawn('npm', ['run', 'child'], {stdio: ['inherit', 'inherit', 'inherit', 'ipc'})
process.send
在我的子腳本中是未定義的。我想這是因爲npm現在正在產生該進程,並且該進程不會繼承我的stdio
設置。也許有一種解決方法。 npm腳本文檔沒有提到該主題。