开发者

PERL-Expect: Get input after sending the command.

开发者 https://www.devze.com 2023-03-24 00:25 出处:网络
I am writing a PERL-Expect script to automate testing. In the script I want to get the warning messages when a command i开发者_运维知识库s executed and take action based on the warning messages. The w

I am writing a PERL-Expect script to automate testing. In the script I want to get the warning messages when a command i开发者_运维知识库s executed and take action based on the warning messages. The warning messages can differ based on some situations and also the warning may not be shown at all.

prompt>delete fs
WARNING: Are you sure?(Y/N).. backup is running:

In the above scenario I need to get the WARNING message as input before proceeding and then do some processing before sending a reply.

The warning may not be displayed as shown below in some cases, for e.g., if backup is not running and command be executed without processing them:

prompt>delete fs
Done.
prompt>show fs
...

How to get the warning message after the command is send if it is displayed?

Thanks.


Going from Expect you'd want to do something like:

 use Expect;

 my $exp = Expect->spawn("delete", "fs")
 or die "Cannot spawn $command: $!\n";

 $exp->expect(360,
   [ "Done." => \&report_success ],
   [ "Are you sure?(Y/N) => sub { my $self = shift;
                                   $self->send("Y\n");
                                   exp_continue; } ],
   [ "backup is running:" => \&report_failure ],
   [ timeout => \&report_timeout ],
 );

 $exp->soft_close();
0

精彩评论

暂无评论...
验证码 换一张
取 消