The same effect can be accomplished fairly easily with a fifo. I'm not aware of a direct piping syntax for doing it (though it would be nifty to see one). This is how you might do it with a fifo.
First, something that prints to both stdout
and stderr
, outerr.sh
:
#!/bin/bash
echo "This goes to stdout"
echo "This goes to stderr" >&2
Then we can do something like this:
$ mkfifo err
$ wc -c err &
[1] 2546
$ ./outerr.sh 2>err | wc -c
20
20 err
[1]+ Done wc -c err
That way you set up the listener for stderr
output first and it blocks until it has a writer, which happens in the next command, using the syntax 2>err
. You can see that each wc -c
got 20 characters of input.
Don't forget to clean up the fifo after you're done if you don't want it to hang around (i.e. rm
). If the other command wants input on stdin
and not a file arg, you can use input redirection like wc -c < err
too.