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

0

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.

python
python-3.x
subprocess
pyinstaller
keylogger
asked on Stack Overflow Dec 22, 2018 by Ali Akhtari • edited Dec 24, 2018 by Flob

1 Answer

5

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

answered on Stack Overflow Dec 22, 2018 by Flob • edited Feb 26, 2019 by Flob

User contributions licensed under CC BY-SA 3.0