As scriptB is interactive, I've set $exp->interact.

You'll have to somehow find a way to quit the requested interactive mode of the root shell, either by interactively typing "exit", or putting the exit on the same line right after the dummy.pl:

my $result = $exp->send("dummy.pl ; exit\n");

or by replacing the shell process with dummy.pl, in which case the end of the su-session will be when the Perl program ends.   I.e., try to exec the command  (works for me):

my $result = $exp->send("exec dummy.pl\n");

Alternatively, you might also just use sudo to run the command (with NOPASSWD configured for whoever is supposed to run the command - see 'man sudoers' for details) — which would also be preferable from a security point of view...


In reply to Re: Switching to non/interactive mode with Expect.pm by almut
in thread 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.