0

I have written a windows gui application using wxPython that is compiled into an executable using py2exe. I'm trying to make the program check for a new version on our website, download it, and then overwrite itself. So far the entire feature is working except that it unsurprisingly can't overwrite a running application (it successfully overwrites all of the supporting files, however). The solution I've devised is that I have it copy the new application executable under a temporary filename and I've written a batch file that will continuously attempt to overwrite the existing file until it succeeds. I've tested this and it also works if I run the batch file independently (i.e. manually). Now my problem, and my question, is: how can I have my application kick off the batch file but not wait for it to finish before exiting so that the batch file can then complete the copy operation?

I've tried the following and they all cause the application to hang:

os.spawnl(os.P_NOWAIT, 'mybatfile.bat')
os.spawnl(os.P_DETACH, 'mybatfile.bat')
os.execl('mybatfile.bat')
Mofi
  • 46,139
  • 17
  • 80
  • 143
kjgregory
  • 656
  • 2
  • 12
  • 23
  • 1
    Have you tried starting a new shell? `os.spawnl(os.P_NOWAIT, 'cmd.exe /C mybatfile.bat')` – lit Nov 01 '15 at 12:25
  • I just tried that, same result. In fact, I tried putting each of these in just a plain python script all by themselves then running the python script and that hangs as well. – kjgregory Nov 01 '15 at 15:09
  • I'm not a Python programmer, but according to [Starting a background process in python](http://stackoverflow.com/questions/1196074/starting-a-background-process-in-python) the method with `os.spawnl(os.P_DETACH, '...')` should work. But you may need `cmd.exe /C "Path to Batch File\mybatfile.bat"` as command to run as a batch file is just a script which needs an interpreter which is command processor `cmd.exe`. – Mofi Nov 01 '15 at 15:45
  • And if your executable creates the batch file, make sure to have the file explicitly closed after writing the commands into the batch file before starting the batch file. – Mofi Nov 01 '15 at 15:49
  • Well I found this site which seems to have me much closer to a solution https://mail.python.org/pipermail/tutor/2000-July/001770.html. I'm now using ```os.spawnv(os.P_DETACH, 'c:\\batpath\\mybat.bat', ['c:\\batpath\\mybat.bat'])```. I'm wondering if the batch file is running in the correct working directory (the directory where it exists). – kjgregory Nov 01 '15 at 16:50

1 Answers1

1

wxPython comes with Esky support built-in. Why not use just that? It is a library for updating frozen applications:

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88