[UNIX]./a. out> outfile 2> & 1 and./a. out 2> & 1> Differences Between outfile

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.