Redirect stderr to stdout
* * * * 1 votos
October 1st, 2006 toydi Posted in pipeline, stderr, stdout | Hits: 15613 |
Very simple, just remember:
- 1 = stdout
- 2 = stderr
In python, its
unittest
module loves to dump test results to stderr (rather than stdout). In order to pipe the results to
less
, you may need to redirect stderr to stdout:
python eggtest.py 2>&1 | less
To redirect stderr into a file:
python eggtest.py 2> result.txt
To redirect both stdout and stderr into a file:
python eggtest.py &> spam.txt
Live Chat!









October 11th, 2006 at 7:51 pm
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 eggtest.py >stdout_file ) >&stderr_file
if ‘>&’ using stdout and stderr will redirect together, and like bash ‘>’ will redirect stdout only