How can I capture the exit status code after running a bash script?

37 views
Skip to first unread message

nagesh....@gmail.com

unread,
Jul 31, 2016, 8:57:26 PM7/31/16
to Yet another Expect for Java
Hello,

I am trying to get the store the status code of the result of a bash script but have been unsuccessful so far. Using v0.8.1.

Here's what I have:

expect.sendLine("bash startScript.sh " + abc + " " + xyz);
expect.expect(contains("$"));
expect.sendLine("echo $?");
String startResult = expect.expect(contains("$")).getBefore();

I am expecting the result of startResult to be 0 if the bash script passes and a non-zero string if it fails, but I keep getting "echo".

Alexey Gavrilov

unread,
Aug 1, 2016, 2:33:03 AM8/1/16
to nagesh....@gmail.com, Yet another Expect for Java
Hi, 

SSH servers normally echo the received commands. 
The echo can be disabled by sending the 'stty -echo’ command before starting the server interaction.

Take a look at the following example of capturing the result of the pwd command when the command echo is switched off:

Regards,
Alexey

--
You received this message because you are subscribed to the Google Groups "Yet another Expect for Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-expecti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nages...@gmail.com

unread,
Aug 1, 2016, 4:45:14 AM8/1/16
to Yet another Expect for Java, nagesh....@gmail.com
Works now! Thanks Alexey!
Reply all
Reply to author
Forward
0 new messages