|
From: Greg M. <la...@ms...> - 2001-11-26 08:13:45
|
I'm doing some mulitline matching of an FTP prompt and I'm having
trouble with a colon (:) in my regex.
The line is:
unless ( $pattern = $ftp->expect($timeout, '-re',
"550 $list/archive/latest/\*:", "226 Transfer complete.\r\nftp> " )){
die "No conditional on ms archive ls to local file, ".$ftp->error()."\n";
}
Actually, I want to map right to the end of the prompt I am
trying to match with the first pattern, but the colon (:) is
screwing things up. Here is the output from exp_internal:
Starting EXPECT pattern matching...^M
Expect::expect('Expect=GLOB(0xbb537c)', 10, '-re', '550 namsook-wei-li/
+archive/latest/*:', '226 Transfer complete.^M^Jftp> ') called at ./down.pl
+line 69
spawn id(3): list of patterns:^M
#1: -re `550 namsook-wei-li/archive/latest/*:'^M
#2: -ex `226 Transfer complete.\r\nftp> '^M
^M
^M
spawn id(3): Does `'^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*:'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
^M
spawn id(3): Does `y\r\n'^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*:'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
^M
spawn id(3): Does `y\r\n200 PORT command successful.\r\012'^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*:'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
^M
spawn id(3): Does `y\r\n200 PORT command successful.\r\012550 namsook-wei-li/
+archive/latest/*: No such file or directory.\r\012ftp> '^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*:'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
No conditional on ms archive ls to local file, 0
I don't know where the ^M come from. No doubt, because I am
running cygwin.
I thought it might be due to the colon being special in regexes,
even though perldoc says they are only after (?: or in POSIX
classes, [: etc. So I tried escaping it, but I get the same
output from exp_internal.
So, I just deleted the colon and tried:
unless ( $pattern = $ftp->expect($timeout, '-re',
"550 $list/archive/latest/\*", "226 Transfer complete.\r\nftp> " )){
die "No conditional on ms archive ls to local file, ".$ftp->error()."\n";
}
Starting EXPECT pattern matching...^M
Expect::expect('Expect=GLOB(0xbb537c)', 10, '-re', '550 namsook-wei-li/
+archive/latest/*', '226 Transfer complete.^M^Jftp> ') called at ./down.pl line
+69
spawn id(3): list of patterns:^M
#1: -re `550 namsook-wei-li/archive/latest/*'^M
#2: -ex `226 Transfer complete.\r\nftp> '^M
^M
^M
spawn id(3): Does `'^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
^M
spawn id(3): Does `y\r\n'^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
^M
spawn id(3): Does `y\r\n200 PORT command successful.\r\012'^M
match:^M
ttern #1: -re `550 namsook-wei-li/archive/latest/*'? No.^M
pattern #2: -ex `226 Transfer complete.\r\nftp> '? No.^M
^M
^M
spawn id(3): Does `y\r\n200 PORT command successful.\r\012550 namsook-wei-li/
+archive/latest/*: No such file or directory.\r\012ftp> '^M
match:^M
pattern #1: -re `550 namsook-wei-li/archive/latest/*'? YES!!^M
Before match string: `y\r\n200 PORT command successful.\r\012'^M
Match string: `550 namsook-wei-li/archive/latest/'^M
After match string: `*: No such file or directory.\r\nftp> '^M
Matchlist: ()^M
So, it apppears the colon is the problem. But wait! the
after-match string still has the asterisk. I escaped the
asterisk. Do I have to double-escape it?
In the lines before this, I am trying to get a listing of files:
print $ftp "nlist $list/archive/latest ../ls\r";
unless ($ftp->expect ($timeout, 'output to local-file: ../ls? ')) {
die "Nlist question broken, ".$ftp->exp_error()."\n";
}
print $ftp "y\r";
I guess this is all academic, because my program is working, but
I remember reading in the expect man page about matching right to
the end of the prompt, and I would like to do that with the
Expect module too.
--
Greg Matheson The best jokes are
Chinmin College those you play on
yourself.
Taiwan Penpals Archive <URL: http://netcity.hinet.net/kurage>
|