Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Howdy peeps, this was originally going to be a private email to module author tye

I would've just replied to tell you to post it someplace like here. I hate the relative waste of my time in answering a question in a way that it can only ever benefit a single person. And it is ludicrous to assume that I am the only person on Earth capable and willing to (partially) answer a question about a module that I had a hand in writing. (:

As to your question, your original code reacts like this for me:

flags was=1 HANDLE_FLAG_PROTECT_FROM_CLOSE=2 Trying for flags=3 Can't SetHandleInformation: The parameter is incorrect, stopped at dontClose.pl line 14.

With minor changes, I can get it to act like it did for you (no complaint but doesn't change anything) or to act like one would expect.

For me, saying that I want to "change" the HANDLE_FLAG_INHERIT value from 1 to 1 (along with changing _PROTECT_FROM_CLOSE from 0 to 1) for one of the STD* handles or a dup(1) of one of them causes the "The parameter is incorrect" error. (This is what your original code does.) Kind of a silly response, sure. But I'd bet money that this is just an undocumented (as near as I can tell) and "varies between versions" behavior of the underlying Windows SetHandleInformation() call.

If I don't specify that I want to "change" the HANDLE_FLAG_INHERIT value (pass in a second argument of 2, not 3) but still use one of the STD* handles (or a dup), then I get the "no complaint but no change" behavior.

If I add an __END__ line and pass in \*DATA to GetOsFHandle() so that I get back a handle to the Perl script (which is an ordinary file), then the flags get updated as desired.

You'll have to find somebody with more knowledge of obscure particulars of the Windows SetHandleInformation() call if you want more than somewhat wild guesses as to why.

I can certainly see it being unsupported to turn off the INHERIT flag on a STD* handle. It seems reasonable to imagine an unfortunate implementation choice that made it illegal to even just try to "keep it on".

I don't have a good guess as to why one isn't permitted to make a STD* handle immune from being closed nor why that prohibition should be silent. It seems even harder to justify such for a dup(1) of a STD* handle. Perhaps this particular impotence applies to all "console" handles? Not that I can think of any guesses as to why that would be.

But maybe somebody here knows more about Windows or can make better guesses or can find better documentation. Or you might have to shop your question to a different audience.

I'm even curious to know why a flag like _PROTECT_FROM_CLOSE was created in the first place. :)

- tye        


In reply to Re: Win32API::File not setting HANDLE_FLAG_PROTECT_FROM_CLOSE (sources) by tye
in thread Win32API::File not setting HANDLE_FLAG_PROTECT_FROM_CLOSE by Yary

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 studying the Monastery: (5)
    As of 2014-12-29 05:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (184 votes), past polls