【发布时间】:2015-04-11 14:34:26
【问题描述】:
我正在编写我的 python 脚本来启动服务器,可能在后台或不同进程中,然后在终止启动的服务器之前进一步做一些处理。
一旦剩下的处理结束,然后杀死启动的服务器。
举例
server_cmd = 'launch_server.exe -source '+ inputfile
print server_cmd
cmd_pid = subprocess.Popen(server_cmd).pid
...
...
... #Continue doing some processing
cmd_pid.terminate() # Once the processing is done, terminate the server
某些脚本在启动服务器后无法继续运行,因为服务器可能在无限循环中运行以侦听请求。有没有一种在后台发送这个进程的好方法,这样它就不需要命令行输入了。
我使用的是 Python 2.7.8
【问题讨论】:
-
能否包含您的完整代码。
标签: python windows subprocess popen