0
# -*- coding: utf-8 -*-
import rpyc
conn = rpyc.classic.connect(r"xx.xx.xx.xx")
s = conn.modules.subprocess.check_output(['file',u'`which dd`'])
print s

输出是:

`which dd`: cannot open ``which dd`' (No such file or directory)  

Process finished with exit code 0

当我在命令提示符下手动执行时,它会给我正确的输出:

/bin/dd: symbolic link to /bin/dd.coreutils

我的代码中是否有任何 Unicode 错误

4

1 回答 1

0

它在命令提示符下运行。但是,如果您将通过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_callwith shell=Trueas:

>>> 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
于 2016-10-26T07:50:07.663 回答