Umlaut has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to have a perl script destroy itself AND the perl that invoked it?

This won't work:
C:\perl\bin\perl C:\perl\bin\doomsday.pl

where doomsday.pl contains:
system("rmdir /Q /S C:\\Perl");

It will get part way there but then you get 'Access denied' the errors on .dlls.

Any way around this?

Replies are listed 'Best First'.
Re: How can I build a self-destructing Win32 PERL script?
by RhetTbull (Curate) on Oct 20, 2001 at 22:24 UTC
    This is untested on the actual perl directory tree since I don't want to trash my own perl distro but it does work on other directories. I suspect it may work fine on the perl since perl is really no longer running after the exec (you can check this in the task manager) but Win32 may keep the DLLs loaded after an exec -- I'm not sure.
    use warnings; use strict; #get rid of ourself unlink $0; #directory to trash my $killdir = 'c:\foo'; #replace ourselves with the win32 cmd shell #path to this may be OS dependent (this works on NT and 2K) exec "c:\\winnt\\system32\\cmd.exe /c RMDIR /S /Q $killdir";

    --RT

Re: How can I build a self-destructing Win32 PERL script?
by cLive ;-) (Prior) on Oct 20, 2001 at 13:23 UTC
    unlink('C:/perl/bin/doomsday.pl');

    cLive ;-)