http://qs321.pair.com?node_id=38228

eisvogel has asked for the wisdom of the Perl Monks concerning the following question:

How to use IPC::Run (with <pty redirect operator) and the batch-mode run routine to execute the ssh1 client, so that can write its stdin and read its stdout and stderr, as handles?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Using IPC::Run to control ssh client
by lachoy (Parson) on Oct 25, 2000 at 04:35 UTC

    The Net::SSH module looks as if it might be useful.

Re: Using IPC::Run to control ssh client
by Lightknight (Beadle) on Sep 02, 2010 at 22:49 UTC

    For some reason, if we start ssh directly, ssh doesn't accept these ptys (and tries to launch ssh askpass). But if we start bash first, and from there launch ssh, it works.

    my $h = start ['bash'], '<pty<', \$in, '>pty>', \$outAndErr, timeo +ut(15); pump $h until $outAndErr =~ /$prompt/; $outAndErr=''; $in .= "ssh user\@host\n"; pump $h until $outAndErr =~ /password:/; $outAndErr=''; $in .= "password\n"; pump $h until $outAndErr =~ /$remotePrompt/; $outAndErr=''; # You're in - do your stuff
    Disclaimer: The original version of the above snippet works, but I've simplified it for this posting, and it is possible there are (minor) bugs in the above.