Need help in Expect Module
Hi,
I am trying to automate a cli application that has multiline output. I
want to be able to grep for this multi line output as single string
using Expect module and send some keys as input.
The cli would be something like
bash-3.00# /opt/myapp/bin/app register
1) someservername(1)
2) someoptionalserver(2)
Select destination server or enter full URL for alternate server
[somedefaultserver(3)]:
How can I do this using Expect?
Thanks in advance..
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Need help in Expect Module
Snippet of what I understand from your requirement:
parag [at] ubuntu-studio:~$ cat app
#!/bin/bash
if [ $# -ne 1 ]
then
echo -e "Invalid number of input\nUsage: app <input>"
exit 1
else
input=$1
fi
if [ $input != "register" ]
then
echo "Invalid choice"
exit 1
fi
echo "mac"
echo "windoze"
echo "Select the server to register:"
echo -n "ubuntu(default):"
read os
case $os in
mac)
echo "rich spoiled brat"
;;
windoze)
echo "old arrogant user"
;;
ubuntu)
echo "smart sexy nerd"
;;
*)
echo "invalid choice"
;;
esac
parag [at] ubuntu-studio:~$
parag [at] ubuntu-studio:~$ cat expect.pl
use strict;
use warnings;
use Expect;
my $app = "./app register";
my [at] oss = qw/ubuntu mac windoze/;
my $choice = $oss[rand [at] oss];
my $exp = new Expect;
$exp->spawn($app) or die "$!\n";
$exp->expect(15,[
qr/default/ =>
sub {
my $ch = shift;
print $ch "$choice\n";
exp_continue;
}
]
);
parag [at] ubuntu-studio:~$
Is this what you want?
~Parag
On Mon, Jan 17, 2011 at 10:19 PM, Zaheer <zaheerlps [at] gmail.com> wrote:
> Hi,
> I am trying to automate a cli application that has multiline output. I
> want to be able to grep for this multi line output as single string
> using Expect module and send some keys as input.
>
> The cli would be something like
>
> bash-3.00# /opt/myapp/bin/app register
>
> 1) someservername(1)
> 2) someoptionalserver(2)
> Select destination server or enter full URL for alternate server
> [somedefaultserver(3)]:
>
> How can I do this using Expect?
>
> Thanks in advance..
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Need help in Expect Module
--0016e6de00140b94fd049b4b4297
Content-Type: text/plain; charset=ISO-8859-1
Thanks a lot Parag.. That was indeed helpful...
On Thu, Jan 20, 2011 at 11:50 AM, Parag Kalra <paragkalra [at] gmail.com> wrote:
> Snippet of what I understand from your requirement:
>
> parag [at] ubuntu-studio:~$ cat app
> #!/bin/bash
> if [ $# -ne 1 ]
> then
> echo -e "Invalid number of input\nUsage: app <input>"
> exit 1
> else
> input=$1
> fi
>
> if [ $input != "register" ]
> then
> echo "Invalid choice"
> exit 1
> fi
>
> echo "mac"
> echo "windoze"
> echo "Select the server to register:"
> echo -n "ubuntu(default):"
> read os
>
> case $os in
>
> mac)
> echo "rich spoiled brat"
> ;;
> windoze)
> echo "old arrogant user"
> ;;
> ubuntu)
> echo "smart sexy nerd"
> ;;
> *)
> echo "invalid choice"
> ;;
> esac
> parag [at] ubuntu-studio:~$
>
> parag [at] ubuntu-studio:~$ cat expect.pl
> use strict;
> use warnings;
> use Expect;
>
> my $app = "./app register";
> my [at] oss = qw/ubuntu mac windoze/;
> my $choice = $oss[rand [at] oss];
>
> my $exp = new Expect;
> $exp->spawn($app) or die "$!\n";
> $exp->expect(15,[
> qr/default/ =>
> sub {
> my $ch = shift;
> print $ch "$choice\n";
> exp_continue;
> }
> ]
> );
>
> parag [at] ubuntu-studio:~$
>
> Is this what you want?
>
> ~Parag
>
>
> On Mon, Jan 17, 2011 at 10:19 PM, Zaheer <zaheerlps [at] gmail.com> wrote:
> > Hi,
> > I am trying to automate a cli application that has multiline output. I
> > want to be able to grep for this multi line output as single string
> > using Expect module and send some keys as input.
> >
> > The cli would be something like
> >
> > bash-3.00# /opt/myapp/bin/app register
> >
> > 1) someservername(1)
> > 2) someoptionalserver(2)
> > Select destination server or enter full URL for alternate server
> > [somedefaultserver(3)]:
> >
> > How can I do this using Expect?
> >
> > Thanks in advance..
> >
> >
> > --
> > To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> > For additional commands, e-mail: beginners-help [at] perl.org
> > http://learn.perl.org/
> >
> >
> >
>
--0016e6de00140b94fd049b4b4297--