Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am retrieving information about my wireless connection by using

In [4]: subprocess.check_output('iwconfig')
eth0      no wireless extensions.

lo        no wireless extensions.

Out[4]: 'wlan0 ...'

I get the string that I want, but I would like to clean the shell from the information about eth0 and lo (notice that these lines are not in the check_ouput return string, they are printed to the shell between ipython's In [4] and Out [4]).

My current guess is that these two lines are considered a warning and are not caught by check_output. Hoping they output to stderr I tried a few variations on

iwconfig > /dev/null 2>&1  # empties my wanted string
iwconfig 2 > /dev/null     # throws an error

but without success so far.

How can I prevent the check_output from outputting anything to the shell?

share|improve this question
up vote 3 down vote accepted

If you want the stderr as your stdout:

subprocess.check_output('iwconfig', stderr=subprocess.STDOUT)

If what you want is just to wipe out your stderr:

import os
subprocess.check_output('iwconfig', stderr=open(os.devnull, 'w'))
share|improve this answer
    
Awesome, thank you ! – user60177 Oct 9 '14 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.