Reputation: 529
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\\\"[email protected]\\\" /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"[email protected]" /usr/local/spool/pf/context/ABC001-1209236.mime]
and I need to match that line.
Upvotes: 3
Views: 363
Reputation: 137767
If you're matching something exactly, just enclose the string in {
braces}
itself. However, you had another problem with your code too: by putting the -ex
outside, you were telling expect
to match the whole lot (including your response code!) as a string. I'd be very startled if that's what your wanted! Move the flag inside the block (this works with Expect's expect
and related commands only) and use the literal string that you're looking for instead of trying to double-guess the number of backslashes. You should get something like this:
expect {
-ex {exec [lp -c -demail -ot"[email protected]" /usr/local/spool/pf/context/ABC001-1209236.mime]} {
incr logged
send_user "\r\n LOGGED #4, $logged \r\n"
}
timeout
}
Upvotes: 1
Reputation: 247142
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"[email protected]" /usr/local/spool/pf} {
incr logged
send_user "\r\n LOGGED #4, $logged \r\n"
}
timeout
}
Upvotes: 2
Reputation: 529
I had to do use *, temporary fix though. But would be great if someone can tell me how to match " " in the text.
My temporary fix is,
expect {
"lp -c -demail -ot*/usr/local/spool/printform" {
}
}
Upvotes: 1