【发布时间】:2016-09-18 22:15:36
【问题描述】:
这个设计让我哭了,下面的代码,请帮助
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: line 0: 意外标记附近的语法错误'ls''\n/bin/sh: -c: line 0:run('ls')'\n”)
【问题讨论】:
-
您是否尝试从您的 python 脚本运行命令
ls?如果是这样,请尝试p=subprocess.Popen("ls",shell=True)。这应该将您当前的所有文件都列出到标准输出中。 -
ls 返回正常,但我需要使用 fabric run 命令列出远程主机
标签: python subprocess fabric