私はpythonが初めてです。目標は、サブプロセス解析を使用してシェル コマンドを実行し、シェルから印刷された出力を取得することです。以下のサンプル出力メッセージに示すように、実行エラーが発生します。また、サンプル コード スニペットを以下に示します。
コードスニペット:
testStr = "cat tst.txt | grep Location | sed -e '/.*Location: //g' "
print "testStr = "+testStr
testStrOut = subprocess.Popen([testStr],shell=True,stdout=subprocess.PIPE).communicate()[0]
出力:
testStr = cat tst.txt | grep Location | sed -e '/.*Location: //g'
cat: tst.txt: No such file or directory
sed: -e expression #1, char 15: unknown command: `/'
使用できる回避策または機能はありますか?
あなたの助けに感謝します ありがとう