从 Python 程序运行 .exe 时终止后台窗口

发布于 2024-08-03 22:39:24 字数 352 浏览 3 评论 0原文

以下是调用“demo.exe”文件的 python 程序中的一行。调用 demo.exe 时会打开一个窗口,有什么方法可以让 demo.exe 在“后台”运行吗?也就是说,我不想显示它的窗口,我只想运行 demo.exe。


p = subprocess.Popen(args = "demo.exe", stdout = subprocess.PIPE)

demo.exe 的输出由 python 程序实时使用,因此 demo.exe 不是我可以在运行 python 程序之前运行的东西。 demo.exe 处理大量动态后端计算。我使用的是Windows XP。

提前致谢!

the following is a line from a python program that calls the "demo.exe" file. a window for demo.exe opens when it is called, is there any way for demo.exe to run in the "background"? that is, i don't want the window for it show, i just want demo.exe to run.


p = subprocess.Popen(args = "demo.exe", stdout = subprocess.PIPE)

the output of demo.exe is used by the python program in real time, so demo.exe is not something that i can have run in advance of running the python program. demo.exe handles a lot of on the fly back-end calculations. i'm using windows xp.

thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小傻瓜 2024-08-10 22:39:24

感谢 另一个 StackOverflow 线程,我认为这就是您所需要的:

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(args = "demo.exe", stdout=subprocess.PIPE, startupinfo=startupinfo)

我测试过在我的 XP 上的 Python 2.6 上,它确实隐藏了窗口。

Thanks to another StackOverflow thread, I think this is what you need:

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(args = "demo.exe", stdout=subprocess.PIPE, startupinfo=startupinfo)

I tested on my Python 2.6 on XP and it does indeed hide the window.

枫林﹌晚霞¤ 2024-08-10 22:39:24

试试这个:

from subprocess import Popen, PIPE, STARTUPINFO, STARTF_USESHOWWINDOW
startupinfo = STARTUPINFO()
startupinfo.dwFlags |= STARTF_USESHOWWINDOW
p = Popen(cmdlist, startupinfo=startupinfo, ...)

Try this:

from subprocess import Popen, PIPE, STARTUPINFO, STARTF_USESHOWWINDOW
startupinfo = STARTUPINFO()
startupinfo.dwFlags |= STARTF_USESHOWWINDOW
p = Popen(cmdlist, startupinfo=startupinfo, ...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文