6

I tried the following code

use strict; 
use warnings;

use Term::ReadPassword::Win32 qw(read_password);

my $pw = read_password('pw: ');
print "pw $pw\n";
my $x = <STDIN>;
print "x: $x\n";

It indeed asks for a password and does not echo the answer but then it skips over the <STDIN> that follows it. I guess this is a bug in Term::ReadPassword::Win32 so I wonder if there is another module that works well on Windows?

szabgab
  • 6,202
  • 11
  • 50
  • 64
  • 4
    http://www.perlmonks.org/?node_id=886306 reports the same issue and provides an alternate read-password implementation using Term::ReadKey. The underlying issue is [this bug](https://rt.cpan.org/Public/Bug/Display.html?id=33513#txn-425619) in Win32::Console, which can be worked around by reopening STDIN and/or STDOUT. – nandhp Jan 18 '12 at 14:20
  • @nandhp You should post your comment as a solution. – JRFerguson Jan 18 '12 at 14:48

1 Answers1

3

http://www.perlmonks.org/?node_id=886306 reports the same issue and provides an alternate read-password implementation using Term::ReadKey. The underlying issue is this bug in Win32::Console, which can be worked around by reopening STDIN and/or STDOUT.

nandhp
  • 4,680
  • 2
  • 30
  • 42