如何避免控制台窗口与.pyw文件包含os.system调用? [英] How to avoid console window with .pyw file containing os.system call?

查看:331
本文介绍了如何避免控制台窗口与.pyw文件包含os.system调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将代码文件保存为 .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.Popen subprocess.call 或其他) code>如果你想避免启动控制台窗口。

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.

这篇关于如何避免控制台窗口与.pyw文件包含os.system调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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