通过 Python Popen 运行长时间运行的进程
所以,我想如果我能用一些 python 魔法一下子让我的开发环境启动并运行,那就太酷了。各种数据库、网络服务器等。
但是,我尝试过的以下每个变体似乎都因“找不到文件”而失败。
p2 = Popen(["exec", "/path/to/redis/server"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
直接从 shell 运行命令(即 exec /path/to/redis/server )效果很好。奇怪的是,一个简单的命令行 uptime
似乎工作得很好。
关于正在发生的事情有任何线索吗?另外,当我们讨论这个主题时,当我想并行运行许多外部进程时,可以使用多重处理吗?
谢谢
So, I thought it would be cool if i could get my dev env up and running in a single fell swoop with some python magic. Various DBs, webserver etc.
However, every variation on the below that i have tried on the following seems to fail with 'file not found'.
p2 = Popen(["exec", "/path/to/redis/server"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
Running the command directly from the shell (i.e. exec /path/to/redis/server
) works just fine. Strangely enough, a simple command line uptime
seems to work fine.
Any clues as to what is going on? Also, whilst we are on the topic, is multiprocessing
the thing to use when i want to run many of these external processes in parallel?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
exec
是 bash 中的内置命令,而不是可执行文件。文件未找到错误可能是由于在$PATH
中找不到 exec 造成的。我会尝试在
Popen
调用中省略“exec”。exec
is a builtin command in bash, not an executable. The file not found error probably comes from exec not being found in the$PATH
.I would try ommitting "exec" in the
Popen
call.