2024-06-12 21:35:39 发布
网友
使用subprocess.call或subprocess.Popen,执行shell命令会使shell窗口快速出现和消失。在
subprocess.call
subprocess.Popen
如果没有shell窗口,如何运行shell命令?在
我想你的观察仅限于Windows,因为我相信,这是唯一一个你会遇到“控制台闪存”问题的平台。如果是这样,那么docs提供以下半有用的段落:
The startupinfo and creationflags, if given, will be passed to the underlying CreateProcess() function. They can specify things such as appearance of the main window and priority for the new process. (Windows only)
不幸的是,Python联机文档没有复制Windows API文档的相关部分,因此您必须在其他地方找到这些文档,例如,在MSDN上启动here,这会导致您here来获得{},特别是
CREATE_NO_WINDOW 0x08000000
The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.
因此,将creationflags=0x08000000添加到您的Popen调用中应该会有所帮助(不幸的是,我没有运行Windows的机器来尝试这一点,所以您必须亲自尝试)。在
creationflags=0x08000000
Popen
我想你的观察仅限于Windows,因为我相信,这是唯一一个你会遇到“控制台闪存”问题的平台。如果是这样,那么docs提供以下半有用的段落:
不幸的是,Python联机文档没有复制Windows API文档的相关部分,因此您必须在其他地方找到这些文档,例如,在MSDN上启动here,这会导致您here来获得{},特别是
因此,将
creationflags=0x08000000
添加到您的Popen
调用中应该会有所帮助(不幸的是,我没有运行Windows的机器来尝试这一点,所以您必须亲自尝试)。在相关问题 更多 >
编程相关推荐