Reputation: 553
I need to establish a dialog between parent and child processes in node.
I started with following:
var child = cp.fork(__dirname + '/Child',[],{silent: true});
Then set up an event handler on parent:
child.stdout.on('data', processChildResponses);
Child listens to stdin and answers writing to stdout. Parent writes to child stdin to send commands:
child.stdin.write("a command...\n");
Then I need to send a variable number of commands to child, some require response, others don't. For those that require response, I must wait for it (let's assume forever to make it simple), process the answer and send another command.
Child was simple because it only waits for a command, answers it and awaits another. So no problem there. But I'm having many problems with parent. Any ideas?
It's an incredibly simple task in java or c# but I would like to make it all in node.
Thanks in advance.
Upvotes: 0
Views: 167
Reputation: 106698
Why not just use child.send() (in parent)/process.send() (in child)? That way you don't have to worry about buffering and parsing stdout and whatnot.
Upvotes: 1