Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!ucsd!ucbvax!GARGOYLE.UCHICAGO.EDU!goer%sophist From: goer%sophist@GARGOYLE.UCHICAGO.EDU (Richard Goerwitz) Newsgroups: comp.lang.icon Subject: Re: non-echoed input Message-ID: <9101181659.AA11351@sophist> Date: 18 Jan 91 16:59:57 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 34 > I am trying to enter a parameter to an Icon program which I don't want echoing > (it's a password). I'm sure I should be able to do this either with getch() or > reads(,1) and then writes(\b*) or something similar, but I can't get it to go. > Has anyone got a solution to this problem? If you are using Unix, you won't be able to access getch(). It can't be done portably. You'll have to do a system() of some kind. E.g.: system("stty -echo") read(&input) system("stty echo") Difficulty: What if, for some reason the system() fails? Oh no! Your password gets echoed! There's no way to test whether system() forked a shell, and that shell couldn't execute the command. You can't tell whether the command worked or not using pipes, for the same reason. All you get is a diagnostic written to stderr by the shell, I believe. Hmmm. Maybe you can do this: instty := open("stty -echo 2>&1","pr") if ("" ~== !instty) then stop("Can't seem to reset your tty to no echo mode.") close(instty) read(&input) Then do the same sort of thing to reset to echo mode. I have an implementation of getch() for UNIX around, but it's not per- fect. And it suffers from the same problem as above. Anyone have any bright ideas, short of hacking a stub that will do an extcall to stty, and then recompiling an idiosyncratic interpreter? -Richard