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

Hi Monks!
I am using Perl v5.6.1 in Solaris and installed Expect module along with IO::TTy and IO::Stty modules and using Expect module to install a s/w. I have prepared a file which conatins question and anwer (say QA.txt) and taking the input from this QA.txt file and supplying to the STDOUT. This is working fine, except the last question. When the last question appears, then it can not send the answer and coming out from the installation.
Here is the format of my QA.txt file
Continue with installation|y Do you wish to continue|y Press RETURN when ready| license|q Do you agree to the terms of the license agreement|y Enter the installation directory|/xxxx
and here is the code to handle expect
open (input, "< QA.txt") while(<input>) { chomp; # no newline s/\#.*//; # no comments s/^\s+//; # no leading white space s/\s+$//; # no trailing white next unless length; # anything left? push (@InputArray, $_); } close (input); my (@Question,@Answer); #Call expect to install my $Install = Expect->spawn("./$FileName") ; for($Index = 0; $Index <= $#InputArray; $Index++) { ($Question[$Index],$Answer[$Index]) = split(/\|/,$InputArray[$Index] +); } for($Index = 0; $Index <= $#InputArray; $Index++) { unless ($Install->expect(200,'-re',$acQuestion[$Index])) { die ("Error::". $Install->exp_error() . "\n"); } print $Install "$Answer[$Index]"; print $Install "\r"; sleep (2); } #close the expect $Install->hard_close();
How can I send the answer of last question?
Thanks in advance.
-Pijush

Replies are listed 'Best First'.
Re: Help needed for expect module!!
by pijush (Scribe) on Dec 20, 2003 at 05:30 UTC
    Hi Monks!

    I have found a solution, but this is a work arround solution. What I did, I have put an extra question in my question answer file which question never appears in the installation. So expect waiting for the last question and send the output of previous question (which is desiable to me). But I am not happy with this solution. Is this a bug of expect module? I have also encountered the same problem when I have used tcl-expect.
    Any explation why this is happening?
    Thanks
    -Pijush