Executing subprocess from Python without opening Windows Command Prompt(从 Python 执行子进程而不打开 Windows 命令提示符)
问题描述
可能重复:
在没有控制台的情况下使用 Popen 在 pythonw 中运行进程一个>
如何消除 Windows 控制台来自 Python (2.7) 中的衍生进程?
我有一个 Python 程序,它多次调用一个单独的数字处理程序(用 C 编写)作为子进程(使用 subprocess.check_call).它在 Linux 上运行良好,在 Windows 上也运行良好,除了一件小事:每次调用子进程时都会创建一个命令提示符窗口,然后在子进程退出时很快将其销毁.
I have a Python program that calls a separate number-crunching program (written in C) as a subprocess several times (using subprocess.check_call). It works great on Linux, and it works great on Windows too except for one little thing: every time it calls the subprocess a Command Prompt window is created and then soon destroyed when the subprocess exits.
这根本不影响计算,但是很烦人,因为这个窗口一直在屏幕上闪烁,并且在计算机上做其他事情变得困难,因为新的命令提示符窗口可以窃取键盘焦点.
This doesn't affect the computation at all, but it's very annoying because this window keeps flashing on and off the screen, and it makes it difficult to do other things on the computer because the new Command Prompt window can steal keyboard focus.
如何简单地执行子进程(没有 GUI),并防止创建命令提示符窗口?
How can I simply execute the subprocess (which has no GUI), and prevent the Command Prompt window from being created?
推荐答案
你是怎么调用subprocess.check_call()
的?如果您传递 shell=True
则不应创建窗口,因为这将导致为 STARTUPINFO.wShowWindow
属性设置 SW_HIDE
标志.
How are you calling subprocess.check_call()
? If you pass shell=True
then the window should not be created as this will cause the SW_HIDE
flag to be set for the STARTUPINFO.wShowWindow
attribute.
例子:
subprocess.check_call(["ping", "google.com"], shell=True)
这篇关于从 Python 执行子进程而不打开 Windows 命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Python 执行子进程而不打开 Windows 命令提示符


基础教程推荐
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01