Redirect stderr to stdout

October 1st, 2006 toydi Posted in pipeline, stderr, stdout | Hits: 142551 | 7 Comments »

Very simple, just remember:

  • 1 = stdout
  • 2 = stderr

In python, its


module loves to dump test results to stderr (rather than stdout). In order to pipe the results to


, you may need to redirect stderr to stdout:

python 2>&1 | less

To redirect stderr into a file:

python 2> result.txt

To redirect both stdout and stderr into a file:

python &> spam.txt

7 Responses to “Redirect stderr to stdout”

  1. This only valid when using bash shell but how about csh? What I have search through internet and what found out is that no direct way to redirect stderr only. The best way is

    ( python >stdout_file ) >&stderr_file

    if ‘>&’ using stdout and stderr will redirect together, and like bash ‘>’ will redirect stdout only

  2. There may be visibly a lot to know regarding it. I suppose you’ve made some good points in features also.

  3. Awsome site! I am loving it!! Will be back later to read some more. I am taking your feeds also Hello. magnificent job. I did not anticipate this. It is a great story. Thanks!

  4. Thanks for the info. Bookmarking this page and coming back later.

  5. Hey, I’m here for the first time here. I found this board and I find It truly useful & it helped me out much. I hope to give something back and aid others like you’ve aided me.

  6. To capture only stderr, try this:

    python 2>&1 > /dev/null | less

  7. En resumidas cuentas, en estfe mundo, cada cual consigue
    lo que se merece. Pero slo quienes alcanzan el exito lo
    reconocen. – Georgges Simenon

    Hecha un ojo y visita mi web site:: consolas videojuegos 2012

Leave a Reply