Getting output after sendLine() command and storing it

84 views
Skip to first unread message

Chung Kim

unread,
Apr 22, 2020, 12:39:07 PM4/22/20
to Yet another Expect for Java
Hello, I've read a couple of posts and looked at a lot of different code examples, but I'm having issues. I would say mine is similar to this post.

Pretty much I am trying to figure out how to extract output from after sendLine() command was sent. So if I send something like "df -h" I want the result of that command.
I'm not too familiar with matchers so if you have good documentation on it that would be greatly appreciated. I feel like this shouldn't be this hard so I apologize in advance,
but I've had no luck trying to play around with the matchers. The purpose of getting the output from the command is to store the results and able to use that elsewhere.

Some of my example code (I'm able to connect successfully):
Channel shell = session.openChannel("shell");
shell.connect();

// Using expect module
Expect expect = new ExpectBuilder()
.withInputs(shell.getInputStream())
.withOutput(shell.getOutputStream())
.withEchoOutput(System.out)
.withEchoInput(System.err)
.withExceptionOnFailure()
.build();
expect.sendLine("df -h");
String str = expect.expect(???)

System.out.println(str);

Chung Kim

unread,
Apr 23, 2020, 10:43:05 AM4/23/20
to Yet another Expect for Java

Chung Kim

unread,
Apr 23, 2020, 12:34:50 PM4/23/20
to Yet another Expect for Java
I am still trying to figure out if there is a way to send the command and then print or store the immediate result after?

Kuldip Patel

unread,
Jun 20, 2022, 9:59:12 AM6/20/22
to Yet another Expect for Java
I m also looking for exactly same but no luck in doing that.. Was wondering why its not straight forward to return the output of what is given in sendLine as command.
Reply all
Reply to author
Forward
0 new messages