|Perl Monk, Perl Meditation|
Re: Unlink Permission Deniedby tachyon (Chancellor)
|on May 03, 2002 at 04:09 UTC||Need Help??|
The problem stems from the fact that under Win32 you can't delete a file that the OS regards as open. Here is an example.
If you close the filehandle opened on $file you can unlink it, if not you get permission denied. When you run your script with an output redirect to a file the OS filehandle on that file is not closed until the shell has finished running your script, ergo you can't delete that redirect file until your script finishes but you need the script running to do the unlink. Catch 22. Solution: write and delete the file from within your script. This works fine:
I can't see any good reason to do it but you can do this on the command line:
PS the or $! == 2 makes no sense to me as $! is unlikely to ever contain a string that evals to 2