在 os.startfile() 中运行时隐藏控制台? [英] hiding console when run in os.startfile()?

查看:34
本文介绍了在 os.startfile() 中运行时隐藏控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有参数的 .bat 文件;我使用 os.startfile(test.bat) 运行它.有没有办法隐藏它的控制台?我尝试使用 subprocess,效果很好,但是当我关闭父程序时,使用 py2exe 控制台模式编译的 subprocess 也会关闭.>

I have a .bat file with parameters; I run it using os.startfile(test.bat). Is there a way to hide its console? I tried using subprocess, it works well but when I close the parent program the subprocess that was compiled using py2exe console mode closes too.

info = subprocess.STARTUPINFO()
info.dwFlags=1
info.wShowWindow=0 
subprocess.Popen(test.bat,startupinfo=info)

谢谢

推荐答案

Use shell=True and creationflags=subprocess.SW_HIDE with subprocess.Popen代码>.这对我有用

Use shell=True and creationflags=subprocess.SW_HIDE with subprocess.Popen. This worked for me

subprocess.Popen(['test.bat'], shell=True, creationflags=subprocess.SW_HIDE)

在一些 Python 版本中,SW_HIDEsubprocess 模块中不可用.在这种情况下,您可能必须使用 _subprocess.SW_HIDE

In some releases of Python, SW_HIDE is not available in subprocess module. In that case, you may have to use _subprocess.SW_HIDE

这篇关于在 os.startfile() 中运行时隐藏控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆