繁体   English   中英

node.js与使用child_process的孩子没有任何互动

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM