Re: [tcljava-user] Expect support
Brought to you by:
mdejong
From: Justin R. <ju...@ha...> - 2007-11-08 19:42:10
|
In the Java space you have a few options for ssh/telnet scripting. The cleanest implementation I've seen is enchanter (1). While expectj (2) is more compliant with actual expect library. I learned this while investigating a expect solution for tcljava, and I also found that my best option was to just write one myself which supports not only expect in java but also the bindings needed for tcljava. The library is called expect4j: http://code.google.com/p/expect4j/ expect4j is aimed at supporting the functionality of the C-based expect library, started by Don Libes, in java and tcljava. The library is written in java and uses a bootstrap class called ExpectEmulation of load the relevant bindings into a tcljava Intrep. The most important tcl functions have been implement, e.g. expect, send, spawn. A full list of supported functions and global variables are commented in ExpectEmulation.java. I've successfully ported a 100K tcl script based on expect to tcljava, without any changes, by just using expect4j. One of the major limitations is that only ssh and telnet are supported by the spawn command. This was done to limit interactions with Runtime.exec(), and to keep the library completely in the java space. This avoids the need for process control, forking, and PTYs. On the otherhand, the Expect4j class can be used for automating any InputStream/OutputStream or Socket. One of the unit tests shows how to automate the "cmd /c net statistics Workstation" command on Windows. For support of ssh/telnet, Jsch is used for ssh and commons-net is used for telnet. The expect command can also match against many different regexps/strings, unlike the other expect-like libraries. ORO is used for the pattern matching. The library is commented and unit tests are used to keep the library in check is expect's original behavior. BUT there is little documentation. For me, expect4j saved the day. If anyone is interested in using this library I'd be happy to walk you through it. I'll use that as motivation for writing the documentation. Justin Ryan Halfempty Industries (1) http://code.google.com/p/enchanter/ (2) http://expectj.sourceforge.net/ On 11/8/07, Mo DeJong <mo...@mo...> wrote: > Chet Vora wrote: > > Hi > > > > Sorry if this is a newbie question but I was wondering if there's > > support for Expect scripts. i.e can I run an expect script using the > > Jacl interpreter ? We use expect primarily for network admin tasks > > like login into devices/term servers via telnet/ssh and run commands. > > Any useful pointers would be appreciated. > > > Hi Chet > > There is zero chance of expect working in Jacl. It depends on low level > IO stuff that Java just > does not support. You could use expect in Tcl Blend though. > > Mo DeJong > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > tcljava-user mailing list > tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tcljava-user > |