ExpecIt error treatment

28 views
Skip to first unread message

Rodolfo Adamshuk Silva

unread,
Aug 23, 2017, 9:15:42 AM8/23/17
to Yet another Expect for Java
Hello,
I just start using ExpectIt and I am having a problem with when the result doesn't match. I got the error message: 
Expect operation fails (timeout: 1000 ms) for matcher: regexp('Execution is halted') and the process got stuck. What can I do to keep the execution of the program even if doesn't match? Thanks.

        try {
            //Init of the expect execution
            Process process = Runtime.getRuntime().exec("/bin/sh");
            Expect expect = new ExpectBuilder()
                    .withInputs(process.getInputStream())
                    .withOutput(process.getOutputStream())
                    .withTimeout(1, TimeUnit.SECONDS)
                    .withEchoInput(System.out)
                    .withEchoOutput(System.err)
                    .withExceptionOnFailure()
                    .build();

            expect.sendLine("cd ..");
            expect.sendLine("cd JPF_HOME/jpf-inspector/src/examples/mtmt/account");
            expect.sendLine();

            expect.sendLine("java -jar /Users/rodolfoadamshuksilva/NetBeansProjects/JPF_HOME/jpf-core/build/RunJPF.jar " + original.getName());
            String list = expect.expect(regexp("\ncmd>")).getBefore();

            expect.sendLine("enable ask scheduling cg");
            expect.sendLine("run");
            list = expect.expect(regexp("\nExecution is halted")).getBefore();

            FileReader fr = new FileReader(record);
            BufferedReader br = new BufferedReader(fr);

            while (br.ready()) {
                String srt = br.readLine();
                if (srt.contains("choice_generators select")) {
                    expect.sendLine(srt);
                    list = expect.expect(regexp("\nExecution is halted")).getBefore();
                }
            }
            expect.sendLine("exit");
            list = expect.expect(regexp("\nterminated")).getBefore();

            br.close();
            fr.close();
            
            expect.close();
            process.destroy();
       } catch (Exception e) {
            System.out.println("Error in expect: " + e.getMessage());
        }

Alexey Gavrilov

unread,
Aug 23, 2017, 10:47:15 AM8/23/17
to Rodolfo Adamshuk Silva, Yet another Expect for Java
You can remove withExceptionOnFailure option which controls whether the exception is going to be thrown if input does not match.

> 23 авг. 2017 г., в 15:15, Rodolfo Adamshuk Silva <rodolfo...@gmail.com> написал(а):
>
> withExceptionOnFailure

Rodolfo Adamshuk Silva

unread,
Aug 23, 2017, 12:21:37 PM8/23/17
to Yet another Expect for Java, rodolfo...@gmail.com
Hey,
Thanks for your answer, but it is still not working. The problem is that the lines are inside a try-catch and every time the expect can't match, it is treated as an exception and the program stuck. I tried to add a throws Exception on the method, but it worked the same. Anything else I can try? Thanks.  

Alexey Gavrilov

unread,
Aug 24, 2017, 1:12:57 AM8/24/17
to Rodolfo Adamshuk Silva, Yet another Expect for Java
Are you sure that If exceptionOnFailure is not selected it still throws a timeout exception?

23 авг. 2017 г., в 18:21, Rodolfo Adamshuk Silva <rodolfo...@gmail.com> написал(а):

--
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