Expect script: How to interrupt (ctrl+c) running script after defined time

35 views Asked by At

I am very new to expect, so I apologize if I don't already know some basic stuff.

I want to run a script (a demo) for 10 seconds and then I need it to be interrupted by Ctrl+C. I cannot let it sleep for 10 seconds and then just send Ctrl+C, because if the demo will stop unexpectedly (very probable) I don't want to wait for 10 seconds for nothing.

Currently I'm using this


    send "sudo stdbuf -oL ./$FILENAME >> out.txt; echo $? &\r"
    expect {
        timeout {
            # everything OK 
            puts "echo demo ran into timeout. Everything OK."
        eof {
            puts "ERROR: Demo stopped unexpectedly."
            exit 1
        }
    }

    }

But this will just crash the script. I need the interrupt, because it is handled in the script and it will trigger some closing commands.

0

There are 0 answers