【发布时间】:2014-12-18 14:52:58
【问题描述】:
我正在从 Python 执行 shell 脚本,到目前为止它运行良好。但我被困在一件事上。
在我的 Unix 机器上,我使用 & 像这样在后台执行一个命令。此命令将启动我的应用服务器 -
david@machineA:/opt/kml$ /opt/kml/bin/kml_http --config=/opt/kml/config/httpd.conf.dev &
现在我需要从我的 Python 脚本中执行相同的操作,但是一旦它执行我的命令,它就永远不会转到 else block 并且永远不会打印出 execute_steps::Successful,它只是挂在那里。
proc = subprocess.Popen("/opt/kml/bin/kml_http --config=/opt/kml/config/httpd.conf.dev &", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable='/bin/bash')
if proc.returncode != 0:
logger.error("execute_steps::Errors while executing the shell script: %s" % stderr)
sleep(0.05) # delay for 50 ms
else:
logger.info("execute_steps::Successful: %s" % stdout)
我在这里做错什么了吗?我想在后台执行shell脚本后打印出execute_steps::Successful。
所有其他命令都可以正常工作,但只有我试图在后台运行的命令不能正常工作。
【问题讨论】:
标签: python linux shell subprocess