[英]node.js no interaction with child using child_process
所有,
嘗試使用node.js來隔離其他人通過node.js中的child_process API創建的JS插件。 我無法讓子進程與父進程進行交互,運行此代碼沒有任何錯誤,但是客戶端無法發送或接收消息,也無法寫入console.log,因此我認為JS沒有運行。 我確實收到一條控制台消息,表明調試器正在從父級和客戶端運行。 代碼幾乎完全來自於node.js API文檔,所以我不確定為什么這行不通。 Windows環境可能有問題嗎?
父代碼:
var fork = require('child_process').fork;
console.log('Starting plugin server...');
var myChild = fork('client.js');
myChild.on('message', function (msg) {
console.log('PARENT got message:', msg)
});
myChild.send({ hello: 'world' });
client.js:
console.log("child");
process.on('message', function (msg) {
console.log('CHILD got message:', msg)
process.send({msg: 'Message receivd & resent from the child.'})
});
process.send({msg: 'Message from the child.'});
輸出:
debugger listening on port 5858
Starting plugin server...
debugger listening on port 5858
我正在使用Windows 8.1,Visual Studio 2013 Pro和用於node.js加載項的新工具。
任何指針表示贊賞。 我是node.js的新手,所以可能犯了一個愚蠢的錯誤?
我在Windows機器上的fork()有問題。 解決方案/解決方法是使用靜默模式和日志記錄。 這是鏈接https://github.com/rogerwang/node-webkit/issues/1516
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.