Re: [tcljava-user] A question involving expect,java and tcl
Brought to you by:
mdejong
From: Patrick F. <pfi...@oz...> - 2008-03-05 15:25:02
|
On Wednesday 05 March 2008 13:04:05 ven...@wi... wrote: > Hi, > > I have a telnet client application written in java. > > The telnet application which is written in java is generally invoked from > my Windows PC as below: java -jar telnetserver.jar <portnumber of the > server> > > I want to interact with this telnet client in a tcl script using Expect. > I read some articles informing that Tclblend allows me to interact with > java application from a Tcl script. But I couldn't find exact information > about how Expect can be used along with java application inside a Tcl > script. > > Please let me know how can I accomplish this task. > > The below snippet is what I'm thinking of using to perform this task. > Please correct me incase I miss something. > > ++++++++++++++++++++++++++++++ > package require Expect > package require Java > > #Spawn a telnet session to the telnet server running on the target device > spawn java -jar telnetserver.jar <port number where Telnet server is > listening> > > expect "*in:" > send "<username>\r" > expect "*Password:" > send "<password>\r" > > #Put a expression which you expect at the command prompt > # For example: > # A prompt like "[anil@Testers anil]$" requires > # expect "*anil]$ " > expect "<expression which we expect at the command prompt><space>" > ++++++++++++++++++++++++++++++++++ > > Thanks In Advance, > Venu Gopal V TclBlend launches it's own Jvm and can act as a java client to a remote java application only if Jvm interprocess communication is available i.e. where an application running on the remote Jvm is configured to listen on a specific port. In your case it seems that the application "telnetserver.jar" runs in a remote Jvm launched by the " java -jar telnetserver.jar" command and listens for telnet connections. Just use expect as the telnet client and spawn a connection to the remote java telnet server from Tcl Blend. package require Expect spawn telnet $host On the other hand if you want to manipulate "telnetserver.jar" then it needs a programming api or a jmx management interface. |