Why does the output of some Linux programs go to neither STDOUT nor STDERR?
Actually, I want to know how to reliably capture all program output, no matter what 'stream' it uses. The problem I have is that some programs do not seem to let their output be captured.
An example is the 'time' command:
time sleep 1 2>&1 > /dev/null
real 0m1.003s
user 0m0.000s
sys 0m0.000s
or
time sleep 1 &> /dev/null
real 0m1.003s
user 0m0.000s
sys 0m0.000s
Why do I see output both times? I expected it all to be piped into /dev/null.
What output stream is time using, and how can I pipe it into a file?
One way to work around the problem is to create a Bash script, for example, combine.sh
containing this command:
$@ 2>&1
Then the output of 'time' can be captured in the correct way:
combine.sh time sleep 1 &> /dev/null
(no output is seen - correct)
Is there a way to achieve what I want without using a separate combine script?
2>&1 > /dev/null
means "2 now goes to where 1 goes (ie, the terminal, by default), and then 1 now goes to /dev/null (but 2 still goes to the terminal!). use>/dev/null 2>&1
to say "1 goes now to /dev/null, then 2 goes to where 1 goes (ie, also to /dev/null) . This still won't work here as the builtin 'time' won't get redirected, but is more generally correct (for example it would work if you use /usr/bin/time). Think about "2>&1" as copying 1's "direction" into 2, not as 2 going to 1