[APUE exercise 3.5]./A. out
> Outfile 2> & 1 and./a. out 2> & 1> Differences Between outfile
Int main ()
{
Printf ("output to stdio \ n ");
Fprintf (stderr, "output to stderr \ n ");
Return 1;
}
The result is as follows:
Qun @ ThinkPad ~ /Tmp $./a. out> outfile 2> & 1
Qun @ ThinkPad ~ /Tmp $ cat outfile
Output to stderr
Output to stdin
Qun @ ThinkPad ~ /Tmp $./a. out 2> & 1> outfile
Output to stderr
The reason is:
Since bash is processed from left to right. /. in the out> outfile. the out fd 1 is directed to the fd of the outfile file, and then 2> & 1 is encountered, and then. in this way, stderr and stdout are all directed to outfile.
But the following one is not the case, first encounter 2> & 1, then. out file descriptor 2 (standard error output) is directed to file descriptor 1 (standard output, that is, terminal. If you encounter> outfile, the file descriptor of a. out is 1 to outfile.
Source: http://hi.baidu.com/malloc_delete/item/b9f9d74f1e31130be8350492