Questions tagged [expectit]

Yet another Java implementation of the Unix expect utility.

ExpectIt - is yet another pure Java 1.6+ implementation of the Expect tool. It is designed to be simple, easy to use and extensible. Written from scratch. Here are the features:

  • Fluent-style API
  • No third-party dependencies
  • NIO based implementation using pipes and non-blocking API
  • Extensible matcher framework
  • Support regular expressions and group operations
  • Support multiple input streams
  • Support 'interact' loop
  • Extensible filter framework to modify the input, for example, to remove non-printable ANSI terminal characters
  • Custom Expect Ant Task
  • Apache License

Example code:

// the stream from where you read your input data
InputStream inputStream = ...;
// the stream to where you send commands
OutputStream outputStream = ...;
Expect expect = new ExpectBuilder()
    .withInputs(inputStream)
    .withOutput(outputStream)
    .build();
expect.sendLine("command").expect(contains("string"));
Result result = expect.expect(regexp("(.*)--?--(.*)"));
// accessing the matching group
String group = result.group(2);
11 questions
1
vote
1 answer

Interactively entering enable mode with Java and expectit

I am doing some maintenance on some network devices and I've been using Expectit to navigate through the menus. However, I've only been successful when the devices provide prompts I expect. For example, some devices are already in enable mode when…
Jon A
  • 362
  • 4
  • 14
1
vote
1 answer

Java Jsch and expect : control an interactive program through SSH

I'm trying to develop an interface used to interact with some programs. I have a windows computer, which will hold the interface, and a Raspberry Pi whcich will launch programs. I've to use them through SSH, but then to interact with : From some…
Aeldred
  • 314
  • 2
  • 15
1
vote
1 answer

ExpectIt: Suppress console echo

Refer: ExpectIt : Trouble implementing a sudo -i How can I avoid echoing all output of Expectit to my java console? This is how I started my SSH: public void connect( String host, String user, String password ) throws Exception { this.host =…
Magno C
  • 1,922
  • 4
  • 28
  • 53
1
vote
1 answer

ExpectIt : Trouble implementing a sudo -i

I'm creating a web shell client and successfully created a simple terminal. I can do basic commands, but I need to do a sudo -i and pass a password. After send the "sudo -i" command, I "expect" the new user (as root) prompt, but the "expect" waits…
Magno C
  • 1,922
  • 4
  • 28
  • 53
0
votes
0 answers

Unable to execute Cutrite commands through SSH

I am trying to execute some Cutrite commands using SSH. These commands work fine when executed directly on the target machine but do not work through the code. The commands do not return any output or error through which I could find the root cause…
Neha P
  • 13
  • 7
0
votes
1 answer

Expectit doesn't find my expected string

I'm trying to use the expectit library with sshj like so: final Session session = getSharedSession(); final Session.Command sessionCommand = session.exec(command); try (Expect expect = new ExpectBuilder() …
schneida
  • 729
  • 3
  • 11
  • 37
0
votes
1 answer

How to send escape keys (ctrl+shift+6) in ExpectIt API

I am new to ExpectIt API. I can execute command and got a response, but I cannot stop running command by giving escape keys (ctrl+shift+6). How do I can send escape keys to the terminal to stop running command through ExpectIt API ? example R1#ping…
Visva
  • 194
  • 1
  • 3
  • 11
0
votes
1 answer

Expectit interact questions need to provide expect for multiple conditions

Java newbie question, I'm attempting to move some of my scripting from Perl based to Java and I have had good luck finding answers in examples here but this one has me stumped. I have tried without success to duplicate similar behavior to Perl…
T Campion
  • 21
  • 4
0
votes
1 answer

error messagejava.io.EOFException: Input closed in expect builder

I am trying connect interactive connection with SSH using java code. I used jsch and expect builder. but it is howing me "error messagejava.io.EOFException: Input closed" in expectbuilder. But same thing I connect through putty it works fine. can…
LowCool
  • 1,187
  • 5
  • 25
  • 51
0
votes
1 answer

How to get the Java stream for ExpectIt to drive Telnet

How do I get the Java stream for telnet to use with the ExpectIt? Instead of using a Java library, such as Apache Telnet as below, using the actual Telnet client on Linux. This is in the context of the man page from expect: Expect is a program…
Thufir
  • 8,216
  • 28
  • 125
  • 273
-1
votes
1 answer

How to iterate a queue during a telnet session?

Having adapted a Tcl script to Java, and using the expectit API, which implements a Java expect, I'm trying to de-clutter the usage below: package expectit; import java.util.logging.Logger; import static…
Thufir
  • 8,216
  • 28
  • 125
  • 273