My Python script is calling a shell command via os.system as:
os.system('sudo ifdown wlan0 &> /dev/null')
If I run this command without Python, the output is suppressed, in Python, however, it still prints the output.
What am I doing wrong?
When you use os.system
, the shell used is /bin/sh
. On many operating systems, /bin/sh
is not bash
. The redirection you are using, &>
, is not defined by POSIX and will not work on some shells such as dash
, which is /bin/sh
on Debian and many of its derivatives. The following should correctly suppress the output:
os.system('sudo ifdown wlan0 > /dev/null 2>&1')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With