2016-12-22 13 views
-2

Pythonで次のサブプロセスコマンドを実行するにはどうすればよいですか?パイプでのサブプロセス呼び出し

$ ps aux|grep python 

>>> subprocess.check_output(['ps', 'aux', 'grep', 'python']) ? 
+0

は、次の2つのサブプロセスは、ps aux' 'のための1つ、'グレップのpython'のために他を作成する必要があります。最初の出力パイプを2番目の入力パイプに接続します。 – Barmar

+2

http://stackoverflow.com/questions/6780035/python-how-to-run-ps-cax-grep-something-in-python –

答えて

-1

は、次の操作を行うことができます。

ps = subprocess.Popen(('ps', 'aux'), stdout=subprocess.PIPE) 
output = subprocess.check_output(('grep', 'python'), stdin=ps.stdout) 
ps.wait() 

print output 
関連する問題