Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] calling telnet from a caml program
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alan Schmitt <alan.schmitt@p...>
Subject: [Caml-list] calling telnet from a caml program
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