Skip Menu |

This queue is for tickets about the Expect CPAN distribution.

Report information
The Basics
Id: 28598
Status: rejected
Priority: 0/
Queue: Expect

People
Owner: Nobody in particular
Requestors: BNEGRAO [...] cpan.org
Cc: RGiersig [...] cpan.org
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



CC: RGiersig [...] cpan.org
Subject: Expect dies if a raw string starts with an "-" (dash character)
If i ask expect to match a raw string that has a "-" in the beginning, the code bellow will assume it is an option string, and if it doesn't find a matching option, expect() croaks with "Unknown option" message. Example, if the raw pattern is: $string = '-bash: line 4: l: command not found\n'; And i try: $exp->expect(1, $string); That line above will croak "Unknown option -bash: line 4: l: command not found". So using the syntax for "raw string" is not actually working as expected, since my raw string is being treated like an option, and not as a raw string. The bugged code is bellow: # not a ref, is an option or raw pattern if (substr($parm, 0, 1) eq '-') { # it's an option print STDERR ("expect(): handling option '$parm'...\n") if $Expect::Debug; if ($parm eq '-i') { # first add collected patterns to object list if (scalar(@$curr_list)) { push @object_list, $curr_list if not exists $patterns{"$curr_list"}; push @{$patterns{"$curr_list"}}, @pattern_list; @pattern_list = (); } # now put parm(s) into current object list if (ref($_[0]) eq 'ARRAY') { $curr_list = shift; } else { $curr_list = [ shift ]; } } elsif ($parm eq '-re' or $parm eq '-ex') { if (ref($_[1]) eq 'CODE') { push @pattern_list, [ $parm_nr, $parm, shift, shift ]; } else { push @pattern_list, [ $parm_nr, $parm, shift, undef ]; } $parm_nr++; } else { croak ("Unknown option $parm"); } Thank you, bruno
Subject: Re: Expect dies if a raw string starts with an "-" (dash character)
On Di. 31. Jul. 2007, 18:22:12, BNEGRAO wrote: Show quoted text
> If i ask expect to match a raw string that has a "-" in the beginning, > the code bellow will assume it is an option string, and if it doesn't > find a matching option, expect() croaks with "Unknown option" message. > > Example, if the raw pattern is: > $string = '-bash: line 4: l: command not found\n'; > > And i try: > $exp->expect(1, $string);
I assume you want to match an exact string, not a regular expression. Then you have to prefix the string with the option '-ex': $exp->expect(1, '-ex', $string); should work as expected. Regards, Roland -- RGiersig@cpan.org
Subject: Re: [rt.cpan.org #28598] Re: Expect dies if a raw string starts with an "-" (dash character)
Date: Wed, 1 Aug 2007 09:06:01 -0300
To: bug-Expect [...] rt.cpan.org
From: "Bruno Negrao" <bnegrao [...] gmail.com>
Ok sorry, This option is kind of undocumented, I reread you full guide many times and I never noticed that. I even looked in your manual if there was any option besides -i and -re but couldn't find any. But after you said, I found this little piece of code in the manual: '-i', [ $objn, ...], '-ex', $exact_pattern, sub { ... }, That's the only mention to '-ex' option. Anyway, thank you. I'm writing a module based on Expect, called Net::SSH::Expect, and I'll publish its new version today. I'll send a note for the people on the expect list. Regards, Bruno. On 8/1/07, Roland Giersig via RT <bug-Expect@rt.cpan.org> wrote: Show quoted text
> > > <URL: http://rt.cpan.org/Ticket/Display.html?id=28598 > > > On Di. 31. Jul. 2007, 18:22:12, BNEGRAO wrote:
> > If i ask expect to match a raw string that has a "-" in the beginning, > > the code bellow will assume it is an option string, and if it doesn't > > find a matching option, expect() croaks with "Unknown option" message. > > > > Example, if the raw pattern is: > > $string = '-bash: line 4: l: command not found\n'; > > > > And i try: > > $exp->expect(1, $string);
> > I assume you want to match an exact string, not a regular expression. > Then you have to prefix the string with the option '-ex': > > $exp->expect(1, '-ex', $string); > > should work as expected. > > Regards, Roland > -- > RGiersig@cpan.org >