-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process.spawn() with 'ipc': has JSON built-in? #48
Comments
By checking the code it seems that ' ipc' assumes JSON based messages with no line break (just one at the end that signals end of message). This is clearly designed for spawning a Node subprocess. What about if my subprocess is not a Node program but a C program? What should I expect in the C side? Which kind of messages should I send from C side? Shouldn't this be documented? |
It's really only intended for communication between node processes but if your C program speaks newline-delimited JSON, there's no reason it wouldn't work. The 'ipc' part is tricky on Windows; the C program needs to know about the ad hoc protocol for sending over handles (unless you let libuv handle that, of course.) |
Thanks a lot. Anyhow I'll feel more comfortable with a simple |
@ibc did you find a good solution to this? I think IPC can be implemented with pipes. I just don't know how Node.js implements IPC, I think there is more than one way to do IPC of course, just not sure how Node.js does it. |
Hi, the doc says:
In my case I call
spawn()
withstdio: ['pipe', 'pipe', 'pipe', 'pipe']
to launch a C+libuv subprocess in which I open thefd
3 to intercommunicate with the Node process and then pass JSON bodies in both directions.According to the doc above, in Node I can do
process.send(JSON_BODY)
andprocess.on('message', function(JSON_BODY)
, but:process.on('message', function(JSON_BODY)
directly provides a JS object? or just a string I need to parse withJSON.parse()
? or a Buffer?process.send()
is totally received in the child process and also that the data/string received inprocess.on('message')
contains all the data written by the subprocess?The text was updated successfully, but these errors were encountered: