daphnaw has asked for the wisdom of the Perl Monks concerning the following question:
(The "exit" command isnt beint called); how can I disable/turn off the interact mode, so I can logoff root and return to my calling script? Thanks Daphnamy $timeout = 5; my $exp = Expect->new; $exp->raw_pty(1); $exp->spawn("su root"); $exp->log_stdout(0); $exp->expect($timeout, [ '-re', 'Password:\s*$' => sub { $exp->send("admin\n"); } ], [ timeout => sub { die "Timeout" } ], ); #waiting for #[root@ana-02 ~]# $exp->expect($timeout, [ '-re', '\][#%]\s*$' => sub {} ], [ timeout => sub { die "Timeout, no prompt" } ], ); $exp->log_stdout(1); my $result = $exp->send("dummy.pl\n"); { #Ignoring :: IO::Stty not installed, cannot change mod +e at test.pl line 22 local $SIG{__WARN__} = sub { my $warn = shift; if ($warn !~ /IO::Stty/) { print STDERR $warn; } }; $exp->interact(); } $exp->log_stdout(0); $exp->expect($timeout, [ '-re', '\][#%]\s*$' => sub { $exp->send(" exit\n"); } ], [ timeout => sub { die "Timeout" } ], ); $exp->soft_close(); my $status = $exp->exitstatus; print "$status\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Switching to non/interactive mode with Expect.pm
by almut (Canon) on May 03, 2010 at 15:18 UTC | |
by daphnaw (Acolyte) on May 04, 2010 at 06:54 UTC |