Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:

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"); }
Running this program on my PC shows the following output:

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>

In reply to Win32: Setting a layer with binmode causes problem with close() on Windows by rovf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-19 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found