Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Windows - have program replace itself

by JediWizard (Deacon)
on Sep 27, 2004 at 15:57 UTC ( #394216=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394216]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2023-02-05 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (32 votes). Check out past polls.

    Notices?