in reply to Re^4: Problem with Windows Console input
in thread Problem with Windows Console input

re-opening STDIN doesn’t solve anshulzunke’s problem:

His problem is that my $StdIn = Win32::Console->new(STD_INPUT_HANDLE); doesn't get a handle to the console input buffer; it get's the handle to it. Thus, as you've correctly surmised, letting it go out of scope means it get closed automatically.

And note. The console input buffer is not the same thing as STDIN. Thought they are normally connected, they are not synonymous. Windows processes can have multiple input buffers; but only one of them can be associated with the console (and thus STDIN) at a time.

One simple solution would be to obtain the handle at the top level scope of the program -- it is a global resource -- and pass that handle into the subroutines.

A perhaps simpler -- and definitely more portable if that is in any way a concern -- solution would be to use Term::ReadKey with ReadMode 2;


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^6: Problem with Windows Console input
by Athanasius (Archbishop) on Feb 25, 2014 at 03:56 UTC

    Yes, thanks, Term::ReadKey is simpler and more portable. Took some trial-and-error for me to get it working correctly, so for the benefit of the OP here is what I came up with:

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,