I'm working on a Python project -- some kind of wake on LAN. For my project, I converted the .py file to an EXE file, and I want to run it without the console window showing. Any ideas on how can I do it?
Asked
Active
Viewed 822 times
0
-
how are you calling the exe file. Which method did you use to convert py to exe. – The6thSense Jan 07 '16 at 06:16
-
I have created a new file using py2exe – Bar Hack Jan 07 '16 at 06:18
2 Answers
1
Use subprocess to make the call:
import os
import subprocess
os.chdir("C:\Temp")
proc = subprocess.Popen('process.exe', creationflags=subprocess.SW_HIDE,shell=True)
proc.wait()
Give a try . It worked for me

coder3521
- 2,608
- 1
- 28
- 50
-
`SW_HIDE` is not a [creation flag](https://msdn.microsoft.com/en-us/library/ms684863). It's a show-window value that gets set in the [`STARTUPINFO`](https://msdn.microsoft.com/en-us/library/ms686331) `wShowWindow`, which is used if `dwFlags` contains `STARTF_USESHOWWINDOW`. The actual value of `SW_HIDE` is 0, so you're pointlessly passing `creationflags=0`. Not that this has any bearing on the OP's problem, but for examples of how this is supposed to work, see [this answer](http://stackoverflow.com/a/7006424). – Eryk Sun Jan 07 '16 at 06:43
-
@eryksun : Great explanation of the answer even i didn't knew this .. Thanks . You edit and add it here .. – coder3521 Jan 07 '16 at 06:47
0
You can also use subprocess.call() if you want. For example,
import subprocess
FNULL = open(os.devnull, 'w') #use this if you want to suppress output to stdout from the subprocess
filename = "my_file.dat"
args = "RegressionSystem.exe -config " + filename
subprocess.call(args, stdout=FNULL, stderr=FNULL, shell=False)
You can read more at this answer.

AddWeb Solution Pvt Ltd
- 21,025
- 5
- 26
- 57
-
-
The issue is that Bar used py2exe to create the executable as a console application instead of as a GUI application. In this case Windows always creates a new console window (conhost.exe) for the program if it doesn't inherit one from the parent process, or if the parent didn't pass either `CREATE_NO_WINDOW` or `DETACHED_PROCESS` in the creation flags. – Eryk Sun Jan 07 '16 at 06:30
-
This has nothing to do with the subprocess module. Even if it did (e.g. if the OP's program was creating a child console process), setting `stdout` and `stderr` has no effect on the creation of a console. Use the `creationflags` parameter for that, or let Windows create the window but hide it via `startupinfo`. – Eryk Sun Jan 07 '16 at 06:31