0

I am writing a PERL-Expect script to automate testing. In the script I want to get the warning messages when a command is 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.

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.