简体   繁体   中英

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

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;

You haven't 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 don't mind piping both STDERR and STDOUT this would be simpler

foo |& node server.js

That is what pipes were made for.

mkfifo needed_stderr
somecommand 2>needed_stderr
node server.js <needed_stderr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM