Hi,
I am new in perl.
I am running a perl installation script, its asking for paths and so many inputs.
Can we provide that info by any file.
so i can avoid the interactive installation.
Hi,
I am new in perl.
I am running a perl installation script, its asking for paths and so many inputs.
Can we provide that info by any file.
so i can avoid the interactive installation.
If you know exactly what questions it will ask, you could put the answers in a file, and then pipe it to the script.
For example:
$ cat myScript
printf "Type y to continue: "
read ans
if [ "$ans" != y ]; then
echo Exiting.
exit 0
fi
printf "Type a number: "
read num
printf "Enter the default bin path: "
read path
echo
echo "You entered the number: $num"
echo "You entered the path: $path"
$ cat answers.txt
y
33
/usr/bin
$ cat answers.txt | ./myScript
Type y to continue: Type a number: Enter the default bin path:
You entered the number: 33
You entered the path: /usr/bin
Otherwise, there's always expect.
Assuming that "config.file" contains the answers in the following format:
question1=answer1
question2=answer2
...
you can try something like this:
my %config;
open (my $fh, "config.file");
while (chomp(my $line=<$fh>)) {
my @fields = split /=/, $line;
$config{$fields[0]}=$fields[1];
}
Then you can access those answers like this:
$config{question1}
$config{question2}