Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask for password on the Windows console in a Perl script?

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?

like image 910
szabgab Avatar asked Jan 18 '12 14:01

szabgab


1 Answers

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.

like image 80
nandhp Avatar answered Sep 21 '22 10:09

nandhp