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

Asked

Viewed 181 times

0

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

1 answer

1


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

Then just create an instance of the secret and hidden class 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, and not a string, since you are not using shell=True.

  • Thanks for the reply. I discovered my mistake. I just needed to put a Try/except in each one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.