How redirections work through pipe?
Posted: 18 Jul 2020 03:31
Handle2 writes to console because stderr is connected to stdout by default. Is this right?
And piped commands could only read from stdin which comes from the stdout of the piping command. So, stderr is not connected to stdout when piping. Is this right?

And piped commands could only read from stdin which comes from the stdout of the piping command. So, stderr is not connected to stdout when piping. Is this right?

Code: Select all
(
echo Output1
echo Output2 >&2
)
echo --- With piping
(
echo Output1
echo Output2 >&2
) | (echo # Running findstr & findstr /A:4E /N "^")
### Result
Output1
Output2
--- With piping
Output2
# Running findstr
1:Output1