in reply to Problem with Windows Console input

Hello anshulzunke, and welcome to the Monastery!

It seems that when the Win32::Console object $StdIn is destroyed, it closes the STDIN filehandle. The solution would be to re-open STDIN in some way. Unfortunately, I don’t know how to do this.

A possible workaround is to keep $StdIn in existence. For example:

... use feature 'state'; ... sub readPasswordWindows { ... state $StdIn = Win32::Console->new(STD_INPUT_HANDLE); ...

This is a kludge, but it does keep STDIN open and so remove the error, allowing the script to run as intended.

Hope that helps,

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

Replies are listed 'Best First'.
Re^2: Problem with Windows Console input
by Anonymous Monk on Feb 24, 2014 at 05:35 UTC
    Thanks buddy it works. But yes there should be a way to re open the stdin handle.
      But yes there should be a way to re open the stdin handle.

      There is:

      #! perl -slw use strict; close STDIN; readline(STDIN); open *STDIN, '<', 'CON:' or die $!; my $x = readline(STDIN); print "Got: $x from reopened STDIN"; __END__ C:\test>junk84.pl readline() on closed filehandle STDIN at C:\test\junk84.pl line 6. fred Got: fred from reopened STDIN

      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.

        Thanks for this! It certainly works as shown. Is it documented anywhere? I haven’t been able to find CON: in either the Perl documentation or Programming Perl. In any case, it seems I was wrong: re-opening STDIN doesn’t solve anshulzunke’s problem:

        1. If I add open *STDIN, '<', 'CON:' or die $!; immediately before the final call to readInput(), the script dies with:

          Bad file descriptor at...
        2. If I add it immediately before return $Password; in sub readPasswordWindows, there is no error but the script generates:

           Use of uninitialized value $ip in concatenation (.) or string at...

          as in the OP.

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

        Thanks for the way for reopening the stdin :)