I think you can still remove Expect from the equation if you can manage a passwordless setup, by providing all the input to SSH via STDIN:
use File::Temp 'tempfile';
my ($fh, $output) = tempfile();
close($fh);
open my $remote, "| ssh $user\@$hostname >$tempfile"
or die "Couldn't launch ssh ssh $user\@$hostname: $!";
print $remote "some test command\n";
print $remote "another test command\n";
print $remote "quit\n";
open my $fh, '<', $tempfile
or die "Couldn't read the tempfile?!";
while(<$fh>) {
print "Remote: $_";
};
But if you need to provide the password to SSH, there is no way to do that without Expect. All of this hinges on the idea of using (passwordless) ssh keys. |