In Python, how to assign stdout, stdin, and stderr to variables, using the module "subprocess" with the hidden console?

0

In Python, how to assign stdout, stdin, and stderr to variables, using the module "subprocess" with the hidden console? Because before I package the program into executable .exe, I can do the normal assignment, but after the program bundled to exe with the pyinstaller, without the command prompt, error console. Can someone help me? Because with the console appearing works, but with the console not hidden, and as my program has graphical interface I do not want console appearing.

    
asked by anonymous 17.07.2018 / 22:00

1 answer

1

First, you can not use shell=True - if you use the shell, it will not work.

Next, just create an instance of the secret class and hide subprocess.STARTUPINFO :

info = subprocess.STARTUPINFO()
info.dwFlags = subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = 0 #SW_HIDE para esconder a janela
p = subprocess.Popen(cmd, 
    stdout=subprocess.PIPE, stderr=subprocess.PIPE,
    stdin=subprocess.PIPE, startupinfo=info,
)

Remembering that cmd has to be a list, with the program and parameters, not a string, since you are not using shell=True .

    
18.07.2018 / 19:23