0

My question relates to a python program I'm using to run multiple times a program by the command prompt. 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). 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. However cmd still show up. Is there a way cmd can start minimized?

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...

Alexander Craggs
  • 7,874
  • 4
  • 24
  • 46
jpcgandre
  • 1,487
  • 5
  • 31
  • 55

2 Answers2

5

You have the "PythonW.exe" program. That runs a Python script but without the console window.

If you really want it minimized, not hidden, you can run it with:

c:\> start /MIN python.exe script.py
rodrigo
  • 94,151
  • 12
  • 143
  • 190
0

Assuming you have win32api for your Python, use win32process.CreateProcess for greater control over process creation. See Demos/winprocess.py for some ways of using it; it sounds like you want either dwCreationFlags=CREATE_NO_WINDOW or startupinfo= a PySTARTUPINFO structure with wShowWindow=SW_SHOWMINIMIZED.

ephemient
  • 198,619
  • 38
  • 280
  • 391
  • Problem is, it appears the [`wShowWindow=SW_SHOWMINIMIZED`](http://stackoverflow.com/questions/12520754/python-windows-popen-with-wshowwindow-in-startupinfo-not-affecting-display) doesn't work. – martineau Sep 23 '12 at 18:28