Normally on unix-like systems a process is started with three open file descriptors. STDIN, STDOUT, STDERR. (Think "standard in", "standard out", "standard error".) Each file descriptor has a traditional use.
Programs read from STDIN. Normally this means the program reads from the console but it is often from a pipe.
Programs write the normal output to STDOUT. Normally this means when the program writes to STDOUT it goes to the console but it is often sent to a pipe.
Programs write error related output to STDERR. Again normally this means when the program writes to STDERR it goes to the console but it is often sent to a pipe.
Note that there is no requirement that the programs you write report errors to STDERR but most unix programs do. The reason is someone might throw away STDOUT because they don't actually want to see it but if an error shows up they do want to see it. For example "some_program > /dev/null".
To see the difference run this program:
#!/usr/bin/perl -w
use strict;
print STDOUT "this is stdout\n";
print STDERR "this is stderr\n";
STDOUT is given the number 1 and STDERR the number 2. (STDIN is number 0, ie zero.) These BASH shell commands will show you what happens when you redirect the different files to the junk bin "/dev/null".
$ ./stdout-stderr.pl 1>/dev/null
this is stderr
$ ./stdout-stderr.pl 2>/dev/null
this is stdout
If you are new to unix programming you should have a look at the
Unix Programming Frequently Asked Questions.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.