|Pathologically Eclectic Rubbish Lister|
Getting filehandle access modes on Windowsby djerius (Beadle)
|on Sep 28, 2012 at 20:40 UTC||Need Help??|
djerius has asked for the
wisdom of the Perl Monks concerning the following question:
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.
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.