2016-10-26 99 views
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 

输出是:错误运行外壳命令与subprocess.check_call()

`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代码错误

回答

0

它在命令提示符下运行。但是,如果你将它称为通过subprocess(所以将与conn.modules.subprocess),它会给你的错误:

>>> subprocess.check_call(['file', '`which python`']) 
`which python`: cannot open ``which python`' (No such file or directory) 

因为在壳,这会被执行为:

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 

为了使上面的命令来看,它与shell=True作为传递的字符串check_call

>>> 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