in reply to Unlink Permission Denied
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Unlink Permission Denied
by rob_au (Abbot) on May 03, 2002 at 05:52 UTC | |
by tachyon (Chancellor) on May 03, 2002 at 06:02 UTC | |
by Marza (Vicar) on May 03, 2002 at 20:16 UTC |