[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Turning off echo on Mac while reading from STDIN



At 11:23 -0700 98/10/13, Rune Fr\xysa wrote:
> I'm porting a unix perl script to Mac, and this code give me some
> problems:
>
> system("stty -echo");
> chop($password = <STDIN>);
> system("stty echo");
>
> Does anyone know how to make this work on a Mac? Preferably without
> any external modules (it's a cross-platform project). Something like
> &MacPerl::AskPassword( "Enter password: "); would haven been useful.

We went through this back in August ;-)  MacPerl doesn't have stty -echo
(yet? :-)  Your solution works on Unix, but on MaMperl you need to dco one
character at a time I/O.

At 14:56 -0700 98/08/05, Vicki Brown wrote:
> Anyhow, you need to get tricky to catch the characters one at a time, and
> process them appropriately.  Presuming you want the user to be able to
> press return and have thet enter the password, try:
>
> #!perl -w
> print "Enter your password: ";
> `stty raw`;
> while (1) {
>    $char = getc() while (!defined($char));
>    if ($char =~ /\n/) {
>         print $char;
>         last;
>    }
>    $pass .= $char;
>    undef $char;
> }
> `stty sane`;
> print "Your password is $pass\n";
> __END__
>
> When run, this produces:
>    Enter your password:
>
>    Your password is foobonnet
>
> (yeah, that's what I typed :-)


Alan Fry <ajf@afco.demon.co.uk> wrote a password.pm module that puts up a
dialog with bullets and all that nice Mac interface stuff; I won't post it
here (Alan may well have a newer version of that code and the list members
frown on large attachments...).
---
Vicki Brown, vlb@cfcl.com        |\      _,,,---,,_
Journeyman Sourceror      ZZZzz /,`.-'`'    -.  ;-;;,_
Scripts & Philtres             |,4-  ) )-,_. ,\ (  `'-'
http://www.cfcl.com/~vlb      '---''(_/--'  `-'\_)
P.O. Box 1269 San Bruno, CA  94066

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch