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 RAA19675; Wed, 6 Nov 2002 17:12:14 +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 RAA19090 for ; Wed, 6 Nov 2002 17:12:13 +0100 (MET) Received: from alan-schm1p.inria.fr (DHCP12-10.CIS.UPENN.EDU [158.130.13.30]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gA6GCC505557 for ; Wed, 6 Nov 2002 17:12:12 +0100 (MET) Received: by alan-schm1p.inria.fr (Postfix, from userid 501) id B143744B9; Wed, 6 Nov 2002 11:11:55 -0500 (EST) Date: Wed, 6 Nov 2002 11:11:55 -0500 From: Alan Schmitt To: caml-list@inria.fr Subject: [Caml-list] calling telnet from a caml program Message-ID: <20021106161155.GD3396@alan-schm1p> Mail-Followup-To: caml-list@inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: 11:07am up 2:42, 1 user, load average: 0.00, 0.00, 0.00 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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