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 WAA28921; Wed, 6 Nov 2002 22:08:14 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA28294 for ; Wed, 6 Nov 2002 22:08:13 +0100 (MET) Received: from alan-schm1p.inria.fr (DHCP12-10.CIS.UPENN.EDU [158.130.13.30]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gA6L8CD26525 for ; Wed, 6 Nov 2002 22:08:12 +0100 (MET) Received: by alan-schm1p.inria.fr (Postfix, from userid 501) id EBDFE44D4; Wed, 6 Nov 2002 16:07:54 -0500 (EST) Date: Wed, 6 Nov 2002 16:07:54 -0500 From: Alan Schmitt To: caml-list@inria.fr Subject: Re: [Caml-list] calling telnet from a caml program Message-ID: <20021106210754.GT3396@alan-schm1p> Mail-Followup-To: caml-list@inria.fr References: <20021106161155.GD3396@alan-schm1p> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021106161155.GD3396@alan-schm1p> User-Agent: Mutt/1.4i X-Editor: Vim http://vim.sf.net/ X-Info: http://pauillac.inria.fr/~aschmitt/ X-Operating-System: Linux/2.4.19-18mdk (i686) X-Uptime: 3:33pm up 7:08, 1 user, load average: 0.02, 0.04, 0.00 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk In response to my own post, if someone has the same problem ... I simply used Cash. Here is the result: let pid, pin, pout, pty_name = Cash.fork_pty_session (fun () -> Cash.exec "/usr/bin/telnet" []) in let str = String.create 1024 in let res = input pin str 0 1024 in print_int res; print_newline (); print_endline str; flush stdout compiled with: ocamlc -I +site-lib/pcre unix.cma str.cma camlp4/camlp4.cma pcre.cma cash.cma main.ml -o test I get: schmitta@localhost:~/SpeedTouchPro> ./test 8 telnet> which is what I wanted ;-) I still have a couple other small issues, but it feels like a giant leap ;-) Alan * Alan Schmitt (alan.schmitt@polytechnique.org) wrote: > Hi, > > I've spent a couple hours trying to make this work, but it does not want > to ... I want to call telnet from a caml program, send some commands, > and read some output. However there is something weird going on, as > telnet does not seem to flush anything. > > I've tried the following: > > let pin,pout = Unix.open_process "/usr/bin/telnet" in > print_endline "got it"; > flush stdout; > output_string pout "open 127.0.0.1\r\n"; > flush pout; > let str = input_line pin in > print_endline str; > output_string pout "quit\r\n"; > flush pout; > print_endline "got it"; > flush stdout > > which does not work (there should at least be the line "Trying > 127.0.0.1") > > and the following (but I am probably completely mistaken about the > handling of pipes): > > let outin, outout = Unix.pipe () in > let inin, inout = Unix.pipe () in > let pid = Unix.create_process "telnet" [| |] inin outout Unix.stderr in > Unix.set_nonblock outin; > let str = String.create 5 in > let res = Unix.read outin str 0 1 in > print_int res; > print_newline (); > print_endline str; > flush stdout > > (this should at least return the "t" of the telnet prompt ... but it > fails with an exception saying there is no data to be read). > > I'd really someone to point to me what I am doing wrong ... > > Best, > > Alan > > > -- > The hacker: someone who figured things out and made something cool happen. > ------------------- > 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 > -- The hacker: someone who figured things out and made something cool happen. ------------------- 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