这样的设计让我哭,下面的代码,请大家帮忙语法错误而使用子
def runbatch(CMD,HOST):
print CMD
print HOST
for host in HOST:
env.host_string=host
print CMD
print env.host_string
print "Execute command : \"%s\" at Host : %s" %(CMD,host)
print "-------------------------------------------------"
p=subprocess.Popen("run('ls')",shell=True,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
output = p.communicate()
print output
错误显示
(无,“/ bin/sh的:-c:0行:靠近意外的标记'ls''\n/bin/sh: -c: line 0:
运行语法错误( 'LS')“\ n”)
你试图从你的python脚本运行'ls'命令吗?如果是这样,请尝试'p = subprocess.Popen(“ls”,shell = True)'。这应该列出当前标准输出中的所有文件。 – TuanDT
ls返回正常,但我需要使用fabric运行命令列出远程主机 – Flasking