caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] calling telnet from a caml program
@ 2002-11-06 16:11 Alan Schmitt
  2002-11-06 16:26 ` Andrei Errapart
  2002-11-06 21:07 ` Alan Schmitt
  0 siblings, 2 replies; 8+ messages in thread
From: Alan Schmitt @ 2002-11-06 16:11 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-11-06 21:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-06 16:11 [Caml-list] calling telnet from a caml program Alan Schmitt
2002-11-06 16:26 ` Andrei Errapart
2002-11-06 16:34   ` Alan Schmitt
2002-11-06 17:20     ` Andrei Errapart
2002-11-06 17:39       ` Nicolas George
2002-11-06 19:51         ` David Brown
2002-11-06 20:56       ` Gerd Stolpmann
2002-11-06 21:07 ` Alan Schmitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).