Article View: borland.public.jbuilder.java.api
Article #2144Re: spawning a telnet session
From: Calvin R. Smith
Date: Wed, 30 May 2001 22:42
Date: Wed, 30 May 2001 22:42
53 lines
2587 bytes
2587 bytes
why not simply use a socket directly instead of trying to control telnet?
But to answer your question, if you want the output of the spawned program
to go to stdout you have to grab the output from the program and then print
it
to stdout yourself I use a class that reads from a reader and writes the
value to
system.out
Calvin
"George Francis" <george.francis@ascom.co.uk> wrote in message
news:3b14bf07$1_2@dnews...
> Hello,
> I'm having difficulty spawning a telnet session from my java app.
> So far I have the following code:
>
> Runtime aRuntime = Runtime.getRuntime();
>
> String host = "127.0.0.1";
> int port = 21;
> try
> {
> Process p = aRuntime.exec("telnet.exe " + host + " " + port);
> InputStream pin = p.getInputStream();
> InputStreamReader cin = new InputStreamReader(pin);
> BufferedReader in = new BufferedReader(cin);
>
> OutputStream pout = p.getOutputStream();
> OutputStreamWriter cout = new OutputStreamWriter(pout);
> BufferedWriter out = new BufferedWriter(cout);
> BufferedWriter out1 = new BufferedWriter(new
> OutputStreamWriter(System.out));
>
> String load = in.readLine();
> System.out.println(load);
> System.setOut(new PrintStream(pout));
> in.close();
>
> }
> catch(java.io.IOException e)
> {
> e.printStackTrace();
> }
>
> As you can probably see, Im not 100% sure what I'm doing. Can someone
tell
> me how to modify this to get the telnet session in either the same dos box
> as the vm or a new one?
> Thanks for any help.
> George.
>
>
Technical Details
Message-ID:
<3b15778b$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!news-out.visi.com!hermes.visi.com!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnewsReferences:
<3b14bf07$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,bf69eaa36dcd1508 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-05-30 16:14:03 PST From: "Calvin R. Smith" <calvinrsmith@hotmail.com> Newsgroups: borland.public.jbuilder.java.api References: <3b14bf07$1_2@dnews> Subject: Re: spawning a telnet session Date: Wed, 30 May 2001 16:42:01 -0600 Lines: 55 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 207.201.104.90 Message-ID: <3b15778b$1_1@dnews> X-Trace: dnews 991262603 207.201.104.90 (30 May 2001 15:43:23 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!news-out.visi.com!hermes.visi.com!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews