#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171

    Std output & std error


    Hi;

    What is the point of std errors? If I know there is an error then I avoid it. Why should I want to "redirect" it to another file?
    Code:
    root@behnam:~# lasdasdasds >> file 2> error
    I am sure I am missing a point here. So can someone give a "real" example?

    Thank you
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,295
    Rep Power
    9400
    By convention, stdout is for normal output from a program and stderr is for error output. That way you can separate the two if needs be.

    Example: a cron job. Normally the output from cron will be emailed to you. If your program outputs normal messages then you probably don't care about them, but if it outputted errors then you would care about those.
    Code:
    /path/to/program >/dev/null
    Or maybe you're running some sort of processing script that generates a lot of output (which you want) but possibly some errors (which you definitely want). Normally you'd get a lot of output at once and it'd be difficult to sift through it while trying to locate error messages, or you can
    Code:
    /path/to/program >output.log 2>error.log
    and look through both log files at your leisure.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171
    Originally Posted by requinix
    By convention, stdout is for normal output from a program and stderr is for error output. That way you can separate the two if needs be.

    Example: a cron job. Normally the output from cron will be emailed to you. If your program outputs normal messages then you probably don't care about them, but if it outputted errors then you would care about those.
    Code:
    /path/to/program >/dev/null
    Or maybe you're running some sort of processing script that generates a lot of output (which you want) but possibly some errors (which you definitely want). Normally you'd get a lot of output at once and it'd be difficult to sift through it while trying to locate error messages, or you can
    Code:
    /path/to/program >output.log 2>error.log
    and look through both log files at your leisure.
    Thanks, getting into cronjob with mysqldump. I guess I will run into this then.
  6. #4
  7. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,959
    Rep Power
    4035
    STDERR is commonly used for status information too. For example if you're downloading a file the progress bar indicating the download status would be printed on STDERR, while the file contents would be printed on STDOUT. With the separate streams, you could redirect STDOUT to a file (or pipe it to a process) while still being able to see the progress bar for the download.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo