Reputation: 2244
Let’s you have a group of commands, and some give error as follows:
begin;
echo “Starting Test";
ls;
bad_command -xyz;
end
If you don’t redirect the output or error the results is as expected i.e.
Starting Test
foo.txt
someotherfile.png
someDir
Unknown command: ‘bad_command’
However, is I pipe the whole block to TextEdit by changing last line to end 2&>1 | open -f -a TextEdit
the error comes first in the file, and the order is messed up. This also happens when piping to other commands. Why does that happen, and how can I prevent that?
Upvotes: 2
Views: 55
Reputation: 455
You are having this problem because pipes will buffer stdout
but not stderr
, and therefore you are getting stderr
output first. The only way to solve this is to not use pipes, and instead redirect your output to a temporary file. Then, work with that file for what you need to do.
Upvotes: 1