recommended way to open a pipe in a child process

52 views
Skip to first unread message

Tim Kuijsten

unread,
Oct 26, 2014, 12:12:12 PM10/26/14
to nod...@googlegroups.com
The docs clearly state that the parent end of a pipe can be opened via the stdio array on the child_process instance. But the docs do not state anything about how to open the pipe in the child. Now with some experimenting I've found that both fs.createReadStream (while skipping the path parameter) and creating a new net.Socket work. It seems like the latter is the most appropriate way of doing this since no variables like path have to be omitted and a duplex stream can be opened right away. I would like to know if using net.Socket is the approved way of opening pipes in a child process and if so, I will create a PR to update the docs.

Ben Noordhuis

unread,
Oct 27, 2014, 10:13:06 AM10/27/14
to nod...@googlegroups.com
Yes, `new net.Socket({ fd: 42 })` is the best and most efficient way
to connect to a pipe or UNIX socket through an existing file
descriptor. `net.connect()` and `net.createConnection()` are
acceptable, too; they delegate to `net.Socket`.

Tim Kuijsten

unread,
Oct 27, 2014, 10:46:01 AM10/27/14
to nod...@googlegroups.com
Ben Noordhuis schreef op 27-10-14 om 12:01:
Great, PR with updated docs: https://github.com/joyent/node/pull/8624
Reply all
Reply to author
Forward
0 new messages