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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.