Skip to content
Advertisement

how ignore warnings to go in stderr

I’m run a command and I want to just get errors in ‍‍‍‍stderr file not warnings

➜  ~ pip2 install 0wned 2> error.txt 

Collecting 0wned
  Using cached https://files.pythonhosted.org/packages/85/fb/af45132a70fa67b7a40383066e284182ae649ce5c2a7839c06da51641a43/0wned-0.6.0-py2.py3-none-any.whl
Installing collected packages: 0wned

➜  ~ cat error.txt 

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/0wned-0.6.0.dist-info'
Consider using the `--user` option or check the permissions.

I want to just get errors in error.txt,not warnings.

I want this output:

➜  ~ cat error.txt

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/0wned-0.6.0.dist-info'
Consider using the `--user` option or check the permissions.

Advertisement

Answer

You can filter the stderr if you want:

 pip2 install 0wned 2> >( grep ERROR > only-errors.txt)

Explanation:

 2> >( command )

Redirect the stderr stream to command

grepv ERROR > only-errors.txt

Copies lines containing ERROR to only-errors.txt file


If you want to keep a copy of all error messages, you can add tee:

 pip2 install 0wned 2> >( tee all.txt |  grep ERROR > only-errors.txt)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement