Ali Akhtari
Ali Akhtari

Reputation: 1298

Python run process as .exe with out opening any console windows

Recently, I tried making a new Key logger and I used this piece of code to run it as background process:

DETACHED_PROCESS = 0x00000008

pid = subprocess.Popen([sys.executable, "KeyLogger.py"],
                       creationflags=DETACHED_PROCESS).pid  

My code works properly when I run this as a python file, but when I convert it to a .exe file using :

pyinstaller --onefile myfile.py

it doesn't work any more. But when I remove this piece of code :

DETACHED_PROCESS = 0x00000008

    pid = subprocess.Popen([sys.executable, "KeyLogger.py"],
                           creationflags=DETACHED_PROCESS).pid   

it works fine. Now, I'm looking for a new way to run my python code as a background process (as .exe) without showing any console windows. In addition, I'm sorry for writing mistakes in my question.

Upvotes: 0

Views: 3462

Answers (1)

Flob
Flob

Reputation: 898

Normally, python files have the extension .py . If you want to run your program without opening a console window, change the extension to .pyw. To convert a .py file to a .exe file (with PyInstaller) which will not open the console, use one of the following commands (see here for more info):

pyinstaller -w yourfile.py

pyinstaller --windowed yourfile.py

pyinstaller --noconsole yourfile.py

Upvotes: 6

Related Questions