Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How can I pipe STDERR to STDIN of the application running inside of bash?

How can I pipe STDERR to STDIN of the application running inside of bash?

Problem

I have a gateway Bash Script. The data being sent to Stderr is the data I want to pipe to the stdin of a application started by the bash script (a nodejs script).

Here is an idea of what I'm trying to do... bash-gateway.sh:

#since STDERR will not continuously send data, i put a neverending while loop
#to wait for data to be present.
while (true);
do

#Read the data from STDERR and send it to server.js STDIN
cat /dev/fd/2 | node server.js;

done;
Problem courtesy of: Jackson Five

Solution

You havent really said what is sending the Bash script the information. So I will assume it to be the program foo for the purpose of this answer. Having said that, you should be able to do something like this if you just need STDERR

foo 2>&1 >/dev/null | node server.js

if you dont mind piping both STDERR and STDOUT this would be simpler

foo |& node server.js
Solution courtesy of: Steven Penny

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How can I pipe STDERR to STDIN of the application running inside of bash?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×