![]() You can also suppress stderr with: subprocess.check_output(, stderr=subprocess.STDOUT) (It actually returns the contents of stdout, so you can use that later in your program if you want.) Example: import subprocess It will suppress stdout and raise an exception if the command fails. Use subprocess.check_output (new in python 2.7). P = Popen(, stdin=PIPE, stdout=DEVNULL, stderr=STDOUT)Īssert p.returncode = 0 # use appropriate for your program error handling here Here's a more portable version (just for fun, it is not necessary in your case): #!/usr/bin/env pythonįrom subprocess import Popen, PIPE, STDOUT For python >= 3.3, Redirect the output to DEVNULL: import os
0 Comments
Leave a Reply. |