How to avoid console window with .pyw file containing os.system call?(如何避免带有包含 os.system 调用的 .pyw 文件的控制台窗口?)
问题描述
如果我将代码文件保存为 .pyw,则不会出现控制台窗口 - 这是我想要的 - 但如果代码包含对 os.system 的调用,我仍然得到一个讨厌的控制台窗口.我认为这是由对 os.system 的调用引起的.有没有办法从我的 .pyw 脚本中执行其他文件而根本不提升控制台窗口?
If I save my code files as .pyw, no console window appears - which is what I want - but if the code includes a call to os.system, I still get a pesky console window. I assume it's caused by the call to os.system. Is there a way to execute other files from within my .pyw script without raising the console window at all?
推荐答案
你可以尝试使用 subprocess 模块(subprocess.Popen、subprocess.call 或其他),如果您想避免启动,请使用参数 shell=True一个控制台窗口.
You could try using the subprocess module (subprocess.Popen, subprocess.call or whatever) with the argument shell=True if you want to avoid starting a console window.
这篇关于如何避免带有包含 os.system 调用的 .pyw 文件的控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何避免带有包含 os.system 调用的 .pyw 文件的控制
基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
