Hi, My application runs on v5.10.1 and Expect.pm v1.21. My perl script (scriptA) is trying to run another script (scriptB) as user root using Expect. As scriptB is inetractive, I've set $exp->interact. However, once scriptB has teminated, it will stay logged in as user root instead of returning to the calling user.
my $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";
(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 Daphna

In reply to Switching to non/interactive mode with Expect.pm by daphnaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.