Perl contains some predefined file handles. For example, standard input stdin and standard outputStdout, And standard errorsStderr. 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! Hiabc
Instead:
Hello, world! Abchi
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 applicable to Unix andLinux. 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.