在没有 shell 窗口的情况下运行 shell 命令
使用 subprocess.call
或 subprocess.Popen
,执行 shell 命令可以使 shell 窗口快速出现和消失。
如何在没有 shell 窗口的情况下运行 shell 命令?
With either subprocess.call
or subprocess.Popen
, executing a shell command makes a shell window quicky appear and disappear.
How can I run the shell command without the shell window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您的观察仅限于 Windows,因为我相信这是您遇到“控制台闪存”问题的唯一平台。如果是这样,那么 文档 提供以下半有帮助的段落:
不幸的是,Python 在线文档不会重现 Windows API 文档的相关部分,因此您必须在其他地方找到它们,例如从 此处位于 MSDN 上,它会引导您此处用于
creationflags
,特别是因此,将
creationflags=0x08000000
添加到您的Popen
调用中应该会有所帮助(不幸的是,我没有运行 Windows 的计算机来尝试此操作,因此您必须尝试一下)你自己)。I imagine your observation is limited to Windows, since that, I believe, is the only platform on which you'll get that "console flash" issue. If so, then the docs offer the following semi-helpful paragraph:
Unfortunately the Python online docs do not reproduce the relevant portion of the Windows API docs, so you have to locate those elsewhere, e.g. starting here on MSDN which leads you here for the
creationflags
, and specifically toSo, adding
creationflags=0x08000000
to yourPopen
call should help (unfortunately I have no Windows-running machine on which to try this out, so you'll have to try it yourself).