Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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?
使用时,使用os.system的外壳是/bin/sh. 在许多操作系统上,/bin/sh不是bash. 您使用的重定向&>, 不是由 POSIX 定义的,并且不适用于某些 shell,例如dashDebian/bin/sh及其许多衍生产品上的 。以下应正确抑制输出:
os.system
/bin/sh
bash
&>
dash
os.system('sudo ifdown wlan0 > /dev/null 2>&1')
tags