它在命令提示符下运行。但是,如果您将通过subprocess
( 也将如此conn.modules.subprocess
) 调用它,它将给您错误:
>>> subprocess.check_call(['file', '`which python`'])
`which python`: cannot open ``which python`' (No such file or directory)
因为在shell中,这将被执行为:
mquadri$ file '`which python`'
`which python`: cannot open ``which python`' (No such file or directory)
但是您想将其运行为:
mquadri$ file `which python`
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
为了使上述命令运行,将其作为字符串传递给check_call
with shell=True
as:
>>> subprocess.check_call('file `which python`', shell=True)
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64