parsing the system prompt

41 views
Skip to first unread message

Jon August

unread,
Jan 20, 2018, 7:05:57 PM1/20/18
to Yet another Expect for Java
Hi,

For a long time, I've been using:

expect.expect(contains("#"));

to wait for the system prompt, but I've been lucky.  Today I found that unexpected results occurred when I found a "#" in the middle of the output of a command.  

I'm surprised this hasn't happened before, but it's probably because I'm not usually very dependent on the responses from the system.

Regardless, I'm wonder if there's a best way to wait for a prompt.  I have considered parsing out and then looking for the full prompt (i.e. hostname#), but I think this could present other complications.

If there's a smarter way, I'd appreciate the help.

Thanks,
   Jon

Jon August

unread,
Jan 20, 2018, 8:00:19 PM1/20/18
to Yet another Expect for Java

OK, here's what I did...  As soon as I got into the system, I send a basic command and look for "#" and collect the Result:

singleResult = expect.expect(contains("#"));

String prompt = singleResult.getInput();
String[] promptLines = prompt.split("\n");
prompt = promptLines[promptLines.length - 1];
prompt = prompt.trim();
System.out.println("PROMPT:---" + prompt + "---");

This seems to do the trick.  Let me know if you have a better solution.  Thanks!

Anurag Shrivastav

unread,
Mar 12, 2018, 5:05:15 PM3/12/18
to Jon August, Yet another Expect for Java
A solution I came across on Perl's Expect FAQ was to echo a special string after every command. Example: (ls; echo -n END_; echo COMMAND). Then search for 'END_COMMAND' to detect command execution completion. 

--
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-expectit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages