0

I wrote a python script which runs a subprocess.Popen("powershell.exe ssh -p ...") and when I run it there is no extra console. I converted it to exe with this command:

pyinstaller.exe --onefile --windowed --icon=icon.ico -F --noconsole app.py

when I run the exe file, it shows an empty console. I tried "powershell.exe -windowstyle hidden ssh ..." but it didn't work.

How can I hide the console?

Ali Ent
  • 1,420
  • 6
  • 17
  • 1
    Read the subprocess module documentation. There are Windows-only flags for this. – Charles Duffy Oct 12 '22 at 21:38
  • `subprocess.CREATE_NO_WINDOW` flag https://docs.python.org/3/library/subprocess.html#windows-constants – Glycerine Oct 12 '22 at 21:52
  • Thank you for your response but unfortunately it's not working, it shows terminal again. – Ali Ent Oct 12 '22 at 21:59
  • @Glycerine am I using it the correct way? `si = subprocess.STARTUPINFO()` `si.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.CREATE_NO_WINDOW` – Ali Ent Oct 12 '22 at 22:12
  • @AliEnt Probably. I believe you can also provide the flags without a startup info object: https://stackoverflow.com/questions/66467245/how-to-use-subprocess-popen-with-multiple-creationflags , https://stackoverflow.com/questions/45104218/subprocess-popen-creationflags - many examples here: https://bitcoden.com/answers/running-a-process-in-pythonw-with-popen-without-a-console – Glycerine Oct 12 '22 at 23:00

1 Answers1

0

Thanks to Glycerine comments I found the problem. I thought that I have to or my flags with subprocess.STARTUPINFO(), but the solution was super simple, the flags should be passed to creationflags input.

process = subprocess.Popen(command, creationflags=subprocess.CREATE_NO_WINDOW)
Ali Ent
  • 1,420
  • 6
  • 17