in reply to Using Net::OpenSSH to su commands

Instead of using spawn, you have to send the command you want to run to the remote shell via its stdin channel:
$expect->send("$command\n");

A better approach is to tell su to run the command directly using the -c flag:

my ($pty, $pid) = $ssh->open2pty({stderr_to_stdout => 1}, 'su', '-c', +$command) or die "Can't open PTY: $!\n";

Replies are listed 'Best First'.
Re^2: Using Net::OpenSSH to su commands
by aztlan667 (Novice) on Mar 06, 2014 at 19:15 UTC

    Thanks for the replies. Yes, I wound up using su -c $command and got it to work. I'm still trying to figure out a good way of getting the exit status. $object->exitstatus doesn't seem to be giving me anything useful. But at least its working!