On 21 mar, 15:11, MRAB <[EMAIL PROTECTED]> wrote: > On Mar 21, 11:48 am, fkallgren <[EMAIL PROTECTED]> wrote:> Hi. > > > I have a little problem. I have a script that is in the scheduler > > (win32). But every now and then I update this script and I dont want > > to go to every computer and update it. So now I want the program to 1) > > check for new version of the script, 2) if there is a new version, > > copy that verision from server to local drive, 3) shutdown the program > > and start it up again as the new version. > > > The problem is that I can't run this script directly from server so it > > have to run it locally. > > > Anyone having any bright ideas?? > > import os > import sys > import shutil > > # Is there a newer version? > my_path = sys.argv[0] > update_path = os.path.join(os.path.dirname(my_path), "new_script.py") > > if os.path.getmtime(my_path) < os.path.getmtime(update_path): > # Update the script. > shutil.copy2(update_path, my_path) > # Re-start the script. > os.startfile(my_path) > sys.exit() > > # The rest of the script...
I do mostly the same, except that instead of os.startfile I use: args = [sys.executable] args.extend(sys.argv) os.spawnl(os.P_NOWAIT, sys.executable, *args) to re-start the current script with the same arguments it was invoked before. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list