rovf has asked for the wisdom of the Perl Monks concerning the following question:
I have an application running on Windows 7 with Perl 5.14, where a file is opened for reading at one place, but the layer is set at a different place using binmode. This has the weird effect that the file can not be deleted, after it is closed, while the process owning the handle is still running. My feeling it that close doesn't work properly, although it doesn't return an error.
Here is a small, complete program which demonstrates the problem:
Running this program on my PC shows the following output:use strict; use warnings; # Some file is created by a different process my $file='ttz'; system("cmd /c echo xx >$file"); # In our application, this file is created by a process # on Unix. That's why we read it with the Unix layer. # We do NOT set the layer during the open call. my $layer=':unix'; open(my $fh,$file) or die "open error $!"; # In our application, a different function is responsible # for setting the layer. Therefore, we use binmode to set # it. Nothing had been read from the file so far, so this # should be fine. binmode($fh,$layer); # Now close the file ... close($fh) or die "close error $!"; # ... and try to delete it. if(!unlink($file)) { # this is line 19 warn $!; system("cmd /c del $file"); }
Permission denied at fcstest1.pl line 19. I:\tmp\ttx The process cannot access the file because it is being used by another + process.
--
Ronald Fischer <ynnor@mm.st>
Ronald Fischer <ynnor@mm.st>
|
---|
Back to
Seekers of Perl Wisdom