Hi. When I run the command haizea -c simulated.conf > result.txt
, the program (haizea
) still prints its output to the screen. But when I try haizea -c simulated.conf 1>& result.txt
, the output is now on the file result.txt
. I'm quite confused about this situation. What is the difference between >
and 1>&
, then?
views:
46answers:
3>
redirects standard output alone.
>&
or &>
or 1>&
redirect both standard output and standard error.
Your program is printing on standard error which is not getting redirected in case 1.
What you're seeing on the terminal is the standard error of your process. Both of these are directed to the same terminal device by default (assuming no redirection put into effect).
The redirection >&xyz
redirects both standard output and error to the file xyz
.
I've never used it but I would think, by extension, that N>&xyz
would redirect file handle N
and standard error to your file. So 1>&xyz
is equivalent to >&xyz
which is also equivalent to >xyz 2>&1
.
The number before the >
stands for the descriptor.
Standard Input - 0
Standard Output - 1
Standard Error - 2
The &
will direct both standard output and standard error.
http://linuxdevcenter.com/pub/a/linux/lpt/13_01.html#doc2ac15b1c13