From: expect <ex...@ih...> - 2002-11-23 20:31:19
|
First I'll try to frame the problem as best as I can. I am using Expect to run sh scripts that are normally used interactively. In the production script different sh scripts are run depending on what's passed to the perl script via Getopt::Long. When choosing one script, things break. But choosing the other sh script, things work fine. The sh scripts are very similar and written using the same sh functions, etc. Now I cut-n-pasted the Expect code, from the perl script that is failing to run the sh script, and created a small version that does just the Expect part and things work as expected (pun). My guesses were that something wonky was going on with redirecting STDOUT and STDERR to log files. But changing those things has not been fruitful. So I am really puzzled as to why this is failing. As a possible clue the sh script seems to pause for ~12 seconds before printing out the final menu choice with the default answer. The menu is displayed using a cat <<EOF --------------------------------- Installation --------------------------------- Menu 1) Create a new install 2) Drop an install 3) QUIT EOF and the final choice query and default answer are displayed using echo " Make a choice: [3] \c" 1>&2 Spawned '/temp/testinstall.sh' spawn id(9) Pid: 794708 Tty: /dev/pts/2 Expect::spawn('Expect', '/temp/testinstall.sh') called at ./testinst.pl line 347 Use of uninitialized value in concatenation (.) or string at /usr/btools/perl/lib/site_perl/5.6.1/Expect.pm line 1386. Closing . Expect::hard_close('Expect=GLOB(0x20589328)') called at /usr/btools/perl/lib/site_perl/5.6.1/Expect.pm line 1575 Expect::DESTROY('Expect=GLOB(0x20589328)') called at ./testinst.pl line 354 eval {...} called at ./testinst.pl line 354 closed. Closing spawn id(9). Expect::soft_close('Expect=GLOB(0x205ab95c)') called at ./testinst.pl line 411 --------------------------------- Installation --------------------------------- Menu 1) Create a new install 2) Drop an install 3) QUIT Timed out waiting for an EOF from spawn id(9). spawn id(9) closed. Pid 794708 of spawn id(9) exited, Status: 0x01 Closing spawn id(9). Expect::hard_close('Expect=GLOB(0x205ab95c)') called at /usr/btools/perl/lib/site_perl/5.6.1/Expect.pm line 1575 Expect::DESTROY('Expect=GLOB(0x205ab95c)') called at ./testinst.pl line 0 eval {...} called at ./testinst.pl line 0 Make a choice: [3] In the debugger (perl -d perlscript) the perl script hangs forever here waiting for something from the sh script: Expect::AUTOLOAD(/usr/btools/perl/lib/site_perl/5.6.1/Expect.pm:274): 274: my $ref = ref($tmp); Expect::AUTOLOAD(/usr/btools/perl/lib/site_perl/5.6.1/Expect.pm:275): 275: return (wantarray? @{$tmp} : $tmp) if ($ref eq 'ARRAY'); Expect::AUTOLOAD(/usr/btools/perl/lib/site_perl/5.6.1/Expect.pm:276): 276: return (wantarray? %{$tmp} : $tmp) if ($ref eq 'HASH'); Expect::AUTOLOAD(/usr/btools/perl/lib/site_perl/5.6.1/Expect.pm:277): 277: return $tmp; Expect::spawn(/usr/btools/perl/lib/site_perl/5.6.1/Expect.pm:124): 124: my $errstatus = sysread(STAT_RDR, $errno, 256); Here's a snippet from a successful run: # /tmp/exptest.pl /tmp/test.cfg Spawned 'testinstall.sh' spawn id(5) Pid: 753842 Tty: /dev/pts/2 Expect::spawn('Expect', 'testinstall.sh') called at /tmp/exptest.pl line 24 Closing . Expect::hard_close('Expect=GLOB(0x204948ec)') called at /usr/btools/perl/lib/site_perl/5.6.1/Expect.pm line 1575 Expect::DESTROY('Expect=GLOB(0x204948ec)') called at /tmp/exptest.pl line 31 eval {...} called at /tmp/exptest.pl line 31 closed. Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x20235440)', undef, '[8]') called at /tmp/exptest.pl line 52 spawn id(5): beginning expect. Timeout: unlimited seconds. Current time: Sat Nov 23 15:01:51 2002 spawn id(5): list of patterns: #1: -ex `[3]' spawn id(5): Does `' match: pattern #1: -ex `[3]'? No. So here I get the "Starting EXPECT pattern matching..." and everything works just as it should. Thanks for any tips you can offer. |