Hi My program was to ask user a password which should be entered with '*' masking. And after user entered the password, user will be asked to enter another Input, text of which will be visible. For linux its ok. But for windows i am trying to use Windows::Console The code is
use warnings; use Win32::Console; sub readPasswordWindows { my $pwdText = shift; my $inputValue = ""; my $StdIn = Win32::Console->new(STD_INPUT_HANDLE); my $orig_mode = $StdIn->Mode(); $StdIn->Mode(ENABLE_PROCESSED_INPUT); my $Password = promptPassword($StdIn, $pwdText, '*'); print "\nPassword = $Password\n"; $StdIn->Mode($orig_mode); return $Password; } sub promptPassword { my ($handle, $prompt, $mask) = @_; my ($Password); local $| = 1; print $prompt; $handle->Flush; while (my $Data = $handle->InputChar(1)) { last if "\r" eq $Data; if ("\ch" eq $Data ) { if ( "" ne chop( $Password )) { print "\ch \ch"; } next; } $Password .= $Data; print $mask; } return $Password; } sub readInput(){ my $ip =""; print " \n Input : "; $ip = <STDIN>; print "\n input was = $ip"; return; } my $pw = readPasswordWindows("Enter password: "); readInput();
......................................... This program gives me error in taking input and says: use of uninitialized value in print for $ip Now if i modify my program a bit by calling the readInput(); as last statement from function promptPassword() it all works fine. The code for which is
use warnings; use Win32::Console; sub readPasswordWindows { my $pwdText = shift; my $inputValue = ""; my $StdIn = Win32::Console->new(STD_INPUT_HANDLE); my $orig_mode = $StdIn->Mode(); $StdIn->Mode(ENABLE_PROCESSED_INPUT); my $Password = promptPassword($StdIn, $pwdText, '*'); print "\nPassword = $Password\n"; $StdIn->Mode($orig_mode); readInput(); return $Password; } sub promptPassword { my ($handle, $prompt, $mask) = @_; my ($Password); local $| = 1; print $prompt; $handle->Flush; while (my $Data = $handle->InputChar(1)) { last if "\r" eq $Data; if ("\ch" eq $Data ) { if ( "" ne chop( $Password )) { print "\ch \ch"; } next; } $Password .= $Data; print $mask; } return $Password; } sub readInput(){ my $ip =""; print " \n Input : "; $ip = <STDIN>; print "\n input was = $ip"; return; } my $pw = readPasswordWindows("Enter password: ");
as far as i am concerned both the programs are same. But a tweaking in program gives problem with using stdin
In reply to Problem with Windows Console input by anshulzunke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |