in reply to Switching to non/interactive mode with Expect.pm

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...

Replies are listed 'Best First'.
Re^2: Switching to non/interactive mode with Expect.pm
by daphnaw (Acolyte) on May 04, 2010 at 06:54 UTC
    Thanks!! it works of course.