简体   繁体   中英

node.js no interaction with child using child_process

All,

Trying to use node.js to isolate JS plugins created by others through the child_process API in node.js. I can't get the child process to interact with the parent, I get no errors running this code but the client can't send or receive messages, or write to console.log, so I assume the JS isn't running. I do get a console message that the debugger is running from both the parent as well as the client. Code is pretty much straight out of the node.js API docs so I'm not sure why this won't work. Perhaps something wrong with the Windows environment?

parent code:

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.'});

Output:

debugger listening on port 5858
Starting plugin server...
debugger listening on port 5858

I'm using Windows 8.1, visual studio 2013 pro with the new tools for node.js add-ins.

Any pointers appreciated. I'm new to node.js so possibly making a silly mistake??

I had problem with fork() on windows machines. Solution/workaround was with silent mode and logging. Here is link https://github.com/rogerwang/node-webkit/issues/1516

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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