From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA17531; Sat, 7 Feb 2004 15:45:47 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA17742 for ; Sat, 7 Feb 2004 15:45:46 +0100 (MET) Received: from mwinf0404.wanadoo.fr (smtp4.wanadoo.fr [193.252.22.27]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i17Ejkf18147 for ; Sat, 7 Feb 2004 15:45:46 +0100 (MET) Received: from morgana (ARennes-303-1-17-244.w81-51.abo.wanadoo.fr [81.51.43.244]) by mwinf0404.wanadoo.fr (SMTP Server) with ESMTP id E25E838000FA; Sat, 7 Feb 2004 15:45:45 +0100 (CET) Received: from david by morgana with local (Exim 4.30) id 1ApTiJ-00015v-SC; Sat, 07 Feb 2004 15:45:43 +0100 To: Basile STARYNKEVITCH Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to read a password without displaying it? References: <87u123rqyn.fsf@linux-france.org> <20040207131730.GA20547@ours.starynkevitch.net> From: David MENTRE Organization: none Date: Sat, 07 Feb 2004 15:45:43 +0100 In-Reply-To: <20040207131730.GA20547@ours.starynkevitch.net> (Basile STARYNKEVITCH's message of "Sat, 7 Feb 2004 14:17:30 +0100") Message-ID: <87d68rrlrc.fsf@linux-france.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 dmentre:01 basile:01 maxence:01 strangely:01 char:01 char:01 stdin:01 stdout:01 stdout:01 dmentre:01 caml:01 flush:01 flush:01 mentre:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Thank you Basile and Maxence for your replies, In fact, I wanted to do that in caml only, to be portable on Windows and I'm relunctant to bind to C code. However, from what you said, it seems impossible. I tried following trick, using '\b' on output. Strangely enough, the output_char have no effect, even if I do a flush. The '*' are printed *after* I do a on my terminal. I don't understand this behavior. The flush should send the caracters to the terminal. let read_password () = let password_chars = ref [] in let loop = ref true in while !loop do let c = input_char stdin in if c <> '\n' then ( password_chars := c :: !password_chars; output_char stdout '\b'; output_char stdout '*'; flush_all (); ) else ( loop := false ) done; let password = String.create (List.length !password_chars) in let _, res = List.fold_right (fun c (i, s) -> s.[i] <- c; (i+1, s)) !password_chars (0, password) in res Yours, d. -- David Mentré ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners