1

I had found this topic and i found this as a solution:

Module subprocess has no attribute 'STARTF_USESHOWWINDOW'

but when I run code reality differs. :/

  1. Run my code:

    # Get the environment variables from OO-Python using subprocess
    oo_py_exec = os.path.join(oo_dir, r'program\python.exe')
    python_oo_script = ' ;'.join([
        "-cimport os",
        "print(os.environ['URE_BOOTSTRAP'])",
        "print(os.environ['UNO_PATH'])",
        "print(os.environ['PATH'])",
    ])
    
    subprocess.STARTF_USESHOWWINDOW
    info = subprocess.STARTUPINFO()
    info.dwFlags = subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE
    process = subprocess.Popen([oo_py_exec, python_oo_script],
        stdout=subprocess.PIPE, startupinfo=info)
    result = process.communicate()
    

Console is showed.

  1. Run code from link:

    kwargs = {}
    if subprocess.mswindows:
         su = subprocess.STARTUPINFO()
         su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
         su.wShowWindow = subprocess.SW_HIDE
         kwargs['startupinfo'] = su 
    subprocess.Popen("cmd.exe", **kwargs)
    

Console is also showed!

win xp, py 2.6

Community
  • 1
  • 1
xliiv
  • 5,399
  • 5
  • 29
  • 35

2 Answers2

1

You shouldn't use python.exe but instead pythonw.exe - those are identical except one does show a console, the other does not (no idea what the w does stand for though).

Voo
  • 29,040
  • 11
  • 82
  • 156
  • I can't use pythonw.exe because OpenOffice.org doesn't have it. – xliiv May 17 '12 at 14:25
  • 3
    I fear python.exe opens a console window itself with the Windows API (i.e. `AllocConsole` presumably), in which case as I understand it `SW_HIDE` is quite useless, because windows itself doesn't create a commandline for it to begin with. My guess anyhow. – Voo May 17 '12 at 14:37
  • I found similar topic: http://stackoverflow.com/questions/3390762/how-do-i-eliminate-windows-consoles-from-spawned-processes-in-python-2-7 which seams very simple explained but still dosen't work. :/ – xliiv May 17 '12 at 18:41
  • I think Voo has it right. You're talking about two Python instances here: the one running your subprocess _and_ the one running your code above. It's the latter, I believe, that is opening a console. – Matthew Trevor May 21 '12 at 04:48
  • @Matthew Trevor Ok i now the reason of the window but still I have no idea how to hide it :( – xliiv May 22 '12 at 08:00
0

Try adding the line: info.wShowWindow=11 This hides the console-window. Problem left: Focus is changed. No idea why, but suppose you run this python code, call an .exe an in the meantime edit a doc. No fun, because your input will go astray lots of the time

Jan
  • 447
  • 6
  • 8