1

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

here is my code

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)
ifconfig
  • 6,242
  • 7
  • 41
  • 65
Karl Jhan
  • 71
  • 1
  • 1
  • 11
  • This is already answered here https://stackoverflow.com/questions/17584698/getting-rid-of-console-output-when-freezing-python-programs-using-pyinstaller – Prayson W. Daniel Nov 24 '19 at 07:14
  • 1
    Does this answer your question? [Getting rid of console output when freezing Python programs using Pyinstaller](https://stackoverflow.com/questions/17584698/getting-rid-of-console-output-when-freezing-python-programs-using-pyinstaller) – Prayson W. Daniel Nov 24 '19 at 07:16
  • @PraysonW.Daniel It's not work for me , I have been try to add --noconsole and change the console value to False. it's still show failed to execute script – Karl Jhan Nov 24 '19 at 08:29
  • Can you paste the trace back error? – Prayson W. Daniel Nov 24 '19 at 13:36
  • @PraysonW.Daniel I found out the problem is about subprocess.Popen https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess , it's no error if comment cmdline(command). but I have no idea how to fix it ? – Karl Jhan Nov 24 '19 at 21:11

0 Answers0