2

I have some complicated Python3 GUI code with tinker, and compiled with cx_Freeze.

The issue only occurs when run on Windows.

subprocess check_ouptut (or Popen) runs a similar command:

import subprocess
VAL = subprocess.check_output(['adb.exe', 'version'], shell=False, stdout=subprocess.PIPE).decode()

So I need to capture the output and store it as VAL. However, when it happens, the cmd window pops up, and closes after the value was read. I have a set of commands those do similar thing, and it results in the adb.exe popping up in a cmd window, which is really annoying.

Is there a way to make these silent, so the cmd does NOT pop up?

As I mentioned, the code is run as GUI/tkinter, compiled with cx_Freeze, and only occurs on Microsoft Windows (does not happen on Linux).

Thank you.

Sazzy
  • 1,924
  • 3
  • 19
  • 27
  • Tried adding \c ? `['adb.exe', '\c', 'version']` – drez90 Mar 25 '14 at 13:55
  • Yes, I tried '\c' but no luck :( – Sazzy Mar 25 '14 at 14:00
  • I know that if you have the tkinter source code, and want to run the GUI with no command window attached, that you just rename the .pyc object file to .pyw ... but as far as compiled with cx_Freeze I don't know... Is the source code available to you? – drez90 Mar 25 '14 at 14:21
  • 4
    Use [`STARTUPINFO`](http://stackoverflow.com/a/7006424/205580). – Eryk Sun Mar 25 '14 at 14:25
  • STARTUPINFO method has worked, thank you! Just to mention, the method only works on Windows, but not on Linux, and I develop on Linux. That will teach me :) – Sazzy Mar 25 '14 at 15:40
  • 1
    BTW, the window that pops up is a console window, not a cmd window. It's created because adb.exe is flagged as a console application, just as cmd.exe is. A new console window is created if one can't be inherited from the parent process. This window is hosted by either csrss.exe or conhost.exe (Windows 7+), so multiple processes can attach to it. – Eryk Sun Mar 25 '14 at 16:25

1 Answers1

4

My solution was:

import subprocess,os
startupinfo = None
if os.platform == 'win32':
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
VAL = subprocess.check_output(['adb.exe', 'version'], shell=False, startupinfo=startupinfo).decode()
Sazzy
  • 1,924
  • 3
  • 19
  • 27