expect.expect(contains(PROMPT)) is executed before script completion expect.sendLine(scriptfile)

51 views
Skip to first unread message

murugavel.r...@gmail.com

unread,
Sep 1, 2017, 4:15:37 AM9/1/17
to Yet another Expect for Java
Dear All,

I have one issues using expectit + jcsh module. Here is the issues description.

expect.expect(contains("#"));
String command = "sh -x /tmp/custom.sh update > /tmp/output.log 2>&1";
expect.sendLine(command);
expect.expect(contains("#"));
expect.sendLine("exit");

When i see the output.log, it seems that half of script output only logged. Inside script, am using for loop command to iterate multilple users to check home dir exists of not, if not create dir accordingly.

But if am going to insert sleep command, then total script output logged correctly.
expect.sendLine(command);
try { Thread.sleep(100000); } catch(Exception ex){}

But i really need a solution, how we can use sleep time incrementally based on the script execution time until final output. If we use less number of loop, then sleep time need to be minimal.

Could you please advice me correct solution if any or how to handle sleep time incrementally in order to complete shell script completion.

Thanks in advance.

Murugavel


Alexey Gavrilov

unread,
Sep 2, 2017, 7:04:36 AM9/2/17
to murugavel.r...@gmail.com, Yet another Expect for Java
Hi,

It’s hard to say what is going without seeing custom.sh.

Anyway, I'd recommend to make custom.sh to report that it finishes processing to the stdout by printing a code word, for example, ‘done'.
Then I'd use the ‘tee’ command to pipe the script output into a file and stdout at the same time, and finally make expect to wait for the code word ‘done’ to appear in stdout. I think that should work.


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.

Reply all
Reply to author
Forward
0 new messages