在没有控制台的情况下使用Popen在pythonw中运行进程

编程入门 行业动态 更新时间:2024-10-21 05:38:18
本文介绍了在没有控制台的情况下使用Popen在pythonw中运行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个程序有一个GUI通过Popen调用运行外部程序:

I have a program with a GUI that runs an external program through a Popen call:

p = subprocess.Popen("<commands>" , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd()) pmunicate()

但是一个控制台弹出,不管我做什么(我也试过传递它的NUL文件句柄)。

But a console pops up, regardless of what I do (I've also tried passing it NUL for the file handle). Is there any way to do that without getting the binary I call to free its console?

推荐答案

从此处:

import subprocess def launchWithoutConsole(command, args): """Launches 'command' windowless and waits until finished""" startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() if __name__ == "__main__": # test with "pythonw.exe" launchWithoutConsole("d:\\bin\\gzip.exe", ["-d", "myfile.gz"])

更多推荐

在没有控制台的情况下使用Popen在pythonw中运行进程

本文发布于:2023-11-08 20:33:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   情况下   进程   Popen   pythonw

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!