-2
Pythonで次のサブプロセスコマンドを実行するにはどうすればよいですか?パイプでのサブプロセス呼び出し
$ ps aux|grep python
>>> subprocess.check_output(['ps', 'aux', 'grep', 'python']) ?
Pythonで次のサブプロセスコマンドを実行するにはどうすればよいですか?パイプでのサブプロセス呼び出し
$ ps aux|grep python
>>> subprocess.check_output(['ps', 'aux', 'grep', 'python']) ?
は、次の操作を行うことができます。
ps = subprocess.Popen(('ps', 'aux'), stdout=subprocess.PIPE)
output = subprocess.check_output(('grep', 'python'), stdin=ps.stdout)
ps.wait()
print output
は、次の2つのサブプロセスは、ps aux' 'のための1つ、'グレップのpython'のために他を作成する必要があります。最初の出力パイプを2番目の入力パイプに接続します。 – Barmar
http://stackoverflow.com/questions/6780035/python-how-to-run-ps-cax-grep-something-in-python –