Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I've just released a module to cpan (IO::ReStoreFH) which stores and restores filehandles and file descriptors. (I'm using it to sandbox code which might mess up the main program's I/O).

It's failing on Windows (thanks, CPAN Testers!) because apparently fcntl on that platform can't be used to determine filehandle access modes. Those are needed to dup them using open according to the documentation:

You may also, in the Bourne shell tradition, specify an EXPR beginning with '>&', in which case the rest of the string is interpreted as the name of a filehandle (or file descriptor, if numeric) to be duped (as dup(2)) and opened. You may use "&" after ">", ">>", "<", "+>", "+>>", and "+<". The mode you specify should match the mode of the original filehandle.
There doesn't seem to be a clean method for getting that info from a filehandle.
  • I can poke at the underlying file descriptor using fcntl, which works on Linux & Mac OS X, but fails on Windows.
  • I can use PerlIO::get_layers( $fh, details => 1) to get the filehandle flags, but the definition of the flags is in a C header and not available directly in Perl.
  • I could use PerlIO::Layers, which gets me everything I need, but it uses XS and I'd like something that's pure Perl, as installing XS code on Windows boxes is not something I wish on anyone.

Is there another option that I've missed? I don't have any experience on Windows (and no machines on which to test code) so I'm kind of poking around in the dark.

Thanks,

Diab


In reply to Getting filehandle access modes on Windows by djerius

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (15)
    As of 2014-07-31 14:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (249 votes), past polls