2016-10-26 105 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