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.
私のPythonスクリプトは、次のようにos.systemを介してシェルコマンドを呼び出しています:
os.system('sudo ifdown wlan0 &> /dev/null')
Python を使用せずにこのコマンドを実行すると、出力は抑制されますが、Python では出力が表示されます。
私は何を間違っていますか?
を使用する場合os.system、使用されるシェルは です/bin/sh。多くのオペレーティング システムで/bin/shは、 は ではありませんbash。使用しているリダイレクト はPOSIX で定義されておらず、Debian およびその派生物の多くにある&>などの一部のシェルでは機能しません。以下は、出力を正しく抑制する必要があります。dash/bin/sh
os.system
/bin/sh
bash
&>
dash
os.system('sudo ifdown wlan0 > /dev/null 2>&1')