I've written auto-updating software (python that was compiled to exe with pyinstaller). everything works just fine, but one problem I just can't solve - I can't close the cmd window after it finishes updating.
let's say the software exe name is software.exe
(this software is single file exe). when started, it checks for updates, if found, it will download it as software.bundle
, and will create a temporary script software-update.bat
on the current directory. this script is registered to be called when software.exe
is closed (using atexit.register).
this script will delete software.exe
and rename software.bundle
to sofware.exe
, will launch software.exe
and will delete atself software-update.bat
.
so the update is working.
the thing is, in order to delete the .exe I need first to completely close it, this means that the command that executes software-update.bat
need to run separately from the main running .exe software.exe
.
i could get it to work only with
os.system(f'start {script_update_name} /b')
(again - this command is starting software-update.bat
and then software.exe
'immediately' exits)
trying to use subprocess.run
or any alternative just resulted with 'Access denied' when trying to delete sofware.exe
from the update script(because software.exe
was apparently still running).
so finally to my question, solving one of the above will solve my problem:
- is there an option to reliably exit cmd window that was stated because of
start ...
command? addingexit
at the end of the script(or any other solution I could find) does not work. - is there an alternative to 'start'? that knows to run bat file separately from the main exe, and yet to exit when finished?
if it helps, here's the update script software-update.bat
:
with open(script_update_name, 'w') as f:
s = dedent(f"""
@echo off
echo Updating...
del {file.__str__()}
rename {(file.parent / done_download_name).__str__()} {osPath.basename(file.__str__())}
start {osPath.basename(file.__str__())}
echo Done
del {script_update_name}
""").strip('\n')
f.write(s)
I know this sounds simple, but honestly, I couldn't solve it by now.
any help would be appreciated!