简体   繁体   English

强制程序最小化启动

[英]Force a program to start minimized

My question relates to a python program I'm using to run multiple times a program by the command prompt. 我的问题与我正在通过命令提示符多次运行某个程序的python程序有关。 However, each time the program is called the cmd window shows up and obstructs the screen and more annoying windows focuses on the cmd window (it brings cmd window to the front). 但是,每次调用该程序时,cmd窗口都会显示并阻塞屏幕,并且更多烦人的窗口会聚焦在cmd窗口上(它将cmd窗口置于最前面)。 I'd like to be able to run the program minimized so that I can continue working without being interrupted. 我希望能够以最小的方式运行该程序,以便我可以继续工作而不会受到干扰。

The code I'm using to call the external program is: 我用来调用外部程序的代码是:

os.system('abaqus cae noGUI=results.py')

If I change py to pyw cmd still pops-up but then hides in about one second and the rest of calculations do not show up. 如果我将py更改为pyw,cmd仍然会弹出,但是会在大约一秒钟后隐藏,其余的计算不会显示。 However cmd still show up. 但是,cmd仍然显示。 Is there a way cmd can start minimized? 有什么方法可以最小化cmd?

I've tried: 我试过了:

def launchWithoutConsole(command, args):
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

    return subprocess.Popen('abaqus cae noGUI=results.py', startupinfo=startupinfo,
                stderr=subprocess.PIPE, stdout=subprocess.PIPE)

But it hangs... 但是挂了...

You have the "PythonW.exe" program. 您具有“ PythonW.exe”程序。 That runs a Python script but without the console window. 它运行一个Python脚本,但没有控制台窗口。

If you really want it minimized, not hidden, you can run it with: 如果您确实希望将其最小化而不是隐藏,则可以使用以下命令运行它:

c:\> start /MIN python.exe script.py

Assuming you have win32api for your Python, use win32process.CreateProcess for greater control over process creation. 假设您的Python使用win32api ,请使用win32process.CreateProcess更好地控制进程创建。 See Demos/winprocess.py for some ways of using it; 有关使用它的一些方法,请参见Demos / winprocess.py it sounds like you want either dwCreationFlags=CREATE_NO_WINDOW or startupinfo= a PySTARTUPINFO structure with wShowWindow=SW_SHOWMINIMIZED . 听起来您想要dwCreationFlags=CREATE_NO_WINDOWstartupinfo=具有wShowWindow=SW_SHOWMINIMIZEDPySTARTUPINFO结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM