From: Roland G. <Rol...@a1...> - 2001-05-19 20:19:44
|
> Ankush wrote: > Expect->exp_init(\*STDIN); What is this supposed to do? It creates an Expect object and attaches STDIN to it so you could parse user input. But as the result isn't stored, it's a NOP. > $object=Expect->spawn("Makefile.PL"); Ahem, Makefile.PL is a perlscript, but it usually isn't executable like a normal script. Instead, this probably should read "perl Makefile.PL". > $object->expect(10,"Enter the apppropriate number [3]:") ; > $object->send(10,'1\r'); This looks strange too. 'send' is just an alias for 'print', so what's the 10 doing in front? Or was this just copied from 'send_slow' (which takes a delay argument)? Also, the string should be in double quotes so the "\r" gets sent as <CR> and not as '\' and 'r'. > $object->exp_match(); > $object->exp_after(); > $object->exp_match_number(); This also doesn't make a lot of sense, as these methods return results about the last expect match, but again, the return values are discarded. > $object->send_slow(10,'1\r'); > $object->hard_close(); > >>>And here is a string of the output > > Waiting for new data (10 seconds)... > spawn id(3): new data. > spawn id(3): EOF > spawn id(3): exit(2304) As you can see here, the spawned command immediately exits with an error code. This is probably due to Makefile.PL not being executable. > spawn id(3): closing... > Closing spawn id(3). > Expect::hard_close('Expect=GLOB(0x82ca850)') called at > /usr/lib/perl5/site_perl/5.005/Expect.pm line 743 > Expect::_multi_expect(10, undef, 'ARRAY(0x82cbe94)') called at > /usr/lib/perl5/site_perl/5.005/Expect.pm line 462 > Expect::expect('Expect=GLOB(0x82ca850)', 10, 'Enter the > apppropriate number [3]:') called at perlexp line 8 > spawn id(3) closed. > Returning from expect with TIMEOUT or EOF > Printed character '1' to spawn id(3). > Printed character '\\' to spawn id(3). > Printed character 'r' to spawn id(3). Here you see that the single quotes prevent the correct interpretation of "\r". > Closing spawn id(3). > Expect::hard_close('Expect=GLOB(0x82ca850)') called at perlexp > line 27 > Closing spawn id(3). > Expect::soft_close('Expect=GLOB(0x82ca850)') called at > /usr/lib/perl5/site_perl/5.005/Expect.pm line 1458 > Expect::DESTROY('Expect=GLOB(0x82ca850)') called at perlexp > line 0 > eval {...} called at perlexp line 0 > > So I dont find my pattern matching.Please let me know where am I > wrong. Please send a sample perlexpect script for "file input output" > if you have any. I'm not sure what you mean by "file input output". The script could be written like this: use Expect; my $object = Expect->spawn("perl Makefile.PL"); $object->expect(10, [ "Enter the appropriate number \[3\]:", sub { my $obj = shift; $obj->send("1\r"); exp_continue; } ], [ "Enter another value: ", sub { my $obj = shift; $obj->send("$value\r"; exp_continue; } ], # we wait for the configuration to be finished [ eof => sub { } ], ); Hope this helps, Roland |