I持って私のPythonスクリプトで、次のステートメント:Pythonのサブプロセス
def run_command(command):
process = subprocess.Popen([sys.executable, command], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retcode = process.wait()
if retcode != 0:
raise Exception, "Problem running command: " + command
stdout, stderr = process.communicate()
return stdout
次の出力が生成されます:
TypeError: unsupported operand type(s) for |: 'str' and 'str'
fun_command()
が関数である
year = '1966'
file = 'test.txt'
cmd = "awk '{FS="|"}{if ($2 == %s) print $1}' %s | sort -n | uniq | wc" % (year, file)
bla = run_command(cmd)
何が間違っていますか?
を使用しています。 – cdarke
知っていますが、プロトタイプ作成にのみ使用します(唯一)。 – Andrej
リストと 'shell = True'を組み合わせることは、普通は悪い考えです。しかし、 'sys.executable'はシェルインタプリタではなく* Python *インタプリタが実行されています。代わりに 'Popen(command、shell = True、...)'を使用してください。 – chepner