Search code examples
tclexpect

Expect Scripting


I am trying to match a text which contains the " ", from the log file. But it doesn't match. I understand that " " has got a special meaning to TCL/Expect.

Hence I tried the following, but no luck.

expect -ex {
            "lp -c -demail -ot\\\"firstname_surname@gmail.com\\\" /usr/local/spool/pf"
            {
               incr logged
               send_user "\r\n LOGGED #4, $logged \r\n"
            }
            timeout

I tried to use , \ and \\ but no luck yet.

My log file contains the following line,

exec [lp -c -demail -ot"firstname_surname@gmail.com"  /usr/local/spool/pf/context/ABC001-1209236.mime]

and I need to match that line.


Solution

  • Use {} quotes, which are similar to shell's single quotes. Also Tcl is sensitive to newlines, so you have to put the opening brace of a block on the previous line

    expect {
        {lp -c -demail -ot"firstname_surname@gmail.com" /usr/local/spool/pf} {
           incr logged
           send_user "\r\n LOGGED #4, $logged \r\n"
         }
         timeout
    }