Firstly you should run your script with:
use strict; use warnings;
If you had, you would have gotten a message that $exp was out of scope when you tried to print it in the final line of your script. You can also enable the maximum debugging level with $update->debug(3), which would give you more information about what is being read and written to the child process.
Where you use Expect->send(...) in your script, you should actually be using the spawned object. So substitute $update->send(...). But in either case, there is no return value from this method.
You might find the example in the documentation instructive, since it gives a way to wait on multiple responses at once. Without knowing what your test application looks like it's hard to know for sure, but you might be able to use something like:
use strict; use warnings; use Expect; # This example assumes that the test script returns "Next Line" after +"y" is pressed my $login ="/my/app/test autoupdate"; my $update = Expect->spawn($login) or die "Can't run autoupdate : $!\n +"; $update->expect(60, [ qr'Update?', sub { print "Sending y"; (shift)->send("y\r"); exp_ +continue; } ], [ qr'Next Line', sub { print "y was accepted"; } ], [ timeout => sub { print "Drag we timed out"; } ], [ eof => sub { print "Ooops, something went wrong"; } ], );
Notice the exp_continue; as the final statement in the "update" clause; this instructs expect to continue on looking for additional matches. Since there is no exp_continue; in the "Next Line" clause, after matching there, expect ends successfully.
In reply to Re: expect send is not working
by Loops
in thread expect send is not working
by starzstar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |