2016-10-26 5 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 error в моем коде

ответ

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 

для того, чтобы сделать вышеуказанную команду бежать, передать его в качестве строки в check_call с shell=True как:

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