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.
$file = 'c:\test.txt'; open F, ">$file" or die "Can't open $file $!\n"; # uncomment this to gain permission to unlink $file... # close F; unlink $file or die "Can't unlink $file $!\n";
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:
$file = "c:\\test.txt"; `dir c: > $file`; unlink $file or die "Can't unlink $file $!\n";
I can't see any good reason to do it but you can do this on the command line:
perl somscript.pl > somefile.txt; del somefile.txt
PS the or $! == 2 makes no sense to me as $! is unlikely to ever contain a string that evals to 2
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: Unlink Permission Denied
by tachyon
in thread Unlink Permission Denied
by Marza
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |