http://qs321.pair.com?node_id=394216


in reply to Windows - have program replace itself

Well if you are copying the new version over the old version, this should work:

exec($0);
May the Force be with you

Replies are listed 'Best First'.
Re^2: Windows - have program replace itself
by sgifford (Prior) on Sep 27, 2004 at 16:31 UTC

    IIRC, the problem is that Windows won't let you overwrite or delete a running program; that's why upgrades of running programs often require a reboot.

    Assuming exec works properly on Windows, one possible workaround would be to launch a second script which would download the first script, then re-execute it:

    # script 1 sub upgrade { exec('upgrade',$0,@ARGV) or die "exec failed! $!\n"; } # upgrade script download_new_version($ARGV[0]); exec(@ARGV) or die "exec failed! $!\n";
Re^2: Windows - have program replace itself
by jdtoronto (Prior) on Sep 27, 2004 at 16:20 UTC
    gee, all of 9 characters, bit excessive?

    LOL

    But serenely elegant if I may say so, thank you very much JediWizard I will give it a try :)

    jdtoronto