"Pipeing" stuff to a child process

45 views
Skip to first unread message

Kevin Ingwersen (Ingwie Phoenix)

unread,
Oct 31, 2014, 10:15:11 AM10/31/14
to nod...@googlegroups.com
So, all unix users know this:

cat myfile | ./someProg

someProg assumes its data to come to STDIN and wouldn’t take other arguments. But, how do we do that in NodeJS? Imagine we have the contents of myfile and just want to spawn a child process of someProg…but then? How do I feed it the stuff it expects?

Kind regards, Ingwie

Alan Hoffmeister

unread,
Oct 31, 2014, 11:50:56 AM10/31/14
to nodejs
Try this http://stackoverflow.com/a/15485424/947885

--
Alan Hoffmeister
https://twitter.com/alan_hoff
https://github.com/alanhoff
https://keybase.io/alanhoff


2014-10-31 2:13 GMT-02:00 Kevin Ingwersen (Ingwie Phoenix)
<ingwi...@googlemail.com>:
> --
> Job board: http://jobs.nodejs.org/
> New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/EE3D76E0-68DD-445E-9187-F503ABFECDB2%40googlemail.com.
> For more options, visit https://groups.google.com/d/optout.

Sam Roberts

unread,
Oct 31, 2014, 4:10:29 PM10/31/14
to nod...@googlegroups.com
c = child_process.spawn(... {
stdio: ['pipe'], // fd 0 is child's stdin
...})

c.stdin.write('hey, you');
Reply all
Reply to author
Forward
0 new messages