Perl contains some predefined file handles. Such as standard input stdin, standard output stdout, and standard error stderr. The standard error stderr is an additional output path. How can we understand this sentence? Let's look at an example.
% Perl-e 'print "Hello, world! \ Nabc "; print stderr" Hi \ n ";'
Output:
Hello, world!
Hi
ABC
Instead:
Hello, world!
ABC
Hi
This is because the Perl print function is a row buffer. When \ n is met, print the "standard output" immediately. Because ABC does not touch the line feed, there is a buffer first, and the buffer is full before printing. The error output is not buffered, so it is printed immediately.
% Perl-e 'print "Hello, world! \ Nabc "; print stderr" Hi \ n "; '> err.txt
Output to err.txt:
Hello, world!
ABC
Err.txt does not contain HI (HI is still output to the screen), but it only imports the standard output to the file. To import standard errors, you must:
% Perl-e 'print "Hello, world! \ Nabc "; print stderr" Hi \ n "; '> &err.txt
> & Only standard error redirection in UNIX and Linux is used. 2 In Windows>
Generally, print is equivalent to the standard output of print stdout. When output to a file, we can use stderr to output the error to the screen. In this way, Perl can instantly see errors (stderr) while working (stdout standard output to files ). (Note: I have always wanted to achieve this before, so I can understand it today .)
For example:
% Perl-e 'print stdout "Hello, world! \ N "; print stderr" error \ n "; '> err.txt
#######
The conclusion is that both stdout and none are the same. Both are standard output and can be output to the screen or redirected to the document.
Stderr is the standard error output, which can be output to the screen or redirected to the document. It is only necessary to add &,
1> OUTFILE 2> & 1 is the standard output, and all error outputs are written to OUTFILE.
Thanks to YC Liucheng and Shangri-la