How to pipe all output streams to another process?
3
votes
1
answer
1113
views
Take the following Bash script
3-output-writer.sh
:
lang-bash
echo A >&1
echo B >&2
echo C >&3
Of course when ran as . 3-output-writer.sh
it gets the error 3: Bad file descriptor
, because Bash doesn't know what to do with the 3rd output stream. One can easily . 3-output-writer.sh 3>file.txt
, though, and Bash is made happy.
But here's the question: how do I pipe all these into another process, so that it would have all three to work with? Is there any way other than creating three named pipes, as in,
lang-bash
mkfifo pipe1 pipe2 pipe3 # prepare pipes
. 3-output-writer.sh 1>pipe1 2>pipe2 3>pipe3 & # background the writer, awaiting readers
3-input-reader pipe1 pipe2 pipe3 # some sort of reader, careful not to block
rm pipe1 pipe2 pipe3
?
Asked by Sinus tentaclemonster
(139 rep)
Aug 6, 2020, 07:30 PM
Last activity: Oct 5, 2024, 01:36 PM
Last activity: Oct 5, 2024, 01:36 PM