Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting stdio from a command in os.system() in Python

Usually I can change stdout in Python by changing the value of sys.stdout. However, this only seems to affect print statements. So, is there any way I can suppress the output (to the console), of a program that is run via the os.system() command in Python?

like image 791
Leif Andersen Avatar asked Jul 07 '10 17:07

Leif Andersen


1 Answers

On a unix system, you can redirect stderr and stdout to /dev/null as part of the command itself.

os.system(cmd + "> /dev/null 2>&1")
like image 134
ealdent Avatar answered Sep 22 '22 07:09

ealdent