RaduH has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

Given this recent experience of mine, I just wanted to share my findings, maybe this'll help others too. In brief, the problem was that I was trying to match the string "Password:" at the end of a longer reply from a server. It was followed by two blanks and I even made sure I got the blanks in order in my template. However, that string just wouldn't be matched. If I used the entire server reply as template, it'd work just fine, but that was unacceptable, as you might imagine.

For reasons I cannot understand (and I'd appreciate it if you could enlighten me) using "Password: " (two blanks at the end on purpose, because this is what the server spits out) doesn't work. However, using 'Password:' (regardless of trailing blanks) does work. I've gone back and read a little about single and double quotes but still cannot figure why the different behavior. There's nothing in my >Password:< string that gets evaluated.

In conclusion, it works, I know why, I don't understand why :)

Replies are listed 'Best First'.
Re: Expect.pm - FYI and question
by samtregar (Abbot) on Oct 29, 2007 at 17:07 UTC
    It's possible those "blanks" weren't spaces. One might have been a tab or the result of a special cursor positioning terminal command. Did you try dumping the output as seen by Expect into a hex editor?

    -sam

      No I have not done that. However, if I add the my "Password: " template the entire text the server is sending my way (such as "Connecting to ..." etc, on previous lines) the match works just fine with double quotes (and I have not touched the blanks when I added the "Connecting to ... " text to the template.
        I'm pretty sure your problem is not the double-quotes. I would focus my attention on the data coming from the server - it may not be what you think it is. I've been using Expect for years, starting with the TCL version, and this kind of problem is very common.

        -sam

Re: Expect.pm - FYI and question
by jasonk (Parson) on Oct 29, 2007 at 19:24 UTC

    A snippet from your original posting:

    spawn id(3): Does `Connecting to <host_ip>...\r\nPassword: ' match: pattern #1: -ex `Password: '? No. Waiting for new data (4 seconds)... TIMEOUT

    Note that the first line clearly shows Password: being followed by a single space, and the match section shows the expect pattern being followed by two spaces. Regardless of how many times you say "(two blanks at the end on purpose, because this is what the server spits out)", the debugging output clearly shows that this is not what the server is spitting out.


    We're not surrounded, we're in a target-rich environment!