BernieC has asked for the wisdom of the Perl Monks concerning the following question:
{ my $sendtext = $_[1] ; # new my $chan = $ssh2->channel() or $ssh2->die_with_error ; $chan->blocking(1) ; #new $chan->exec("($_[0]) 2>&1") ; my $write = $chan->write($sendtext) ; #new $ssh2->die_with_error() unless $write ; #new if ($write != length($sendtext)) #new { die "Only $write bytes were sent!\n" ; } #new my $out = ""; while (!$chan->eof) { my $buffer = ""; if (not defined ($chan->read($buffer, 100))) { $ssh2->die_with_error() ; } $out .= $buffer ; }
I checked by calling it with docmd("cat >sshfile", "this is a test")and I was delighted to see
~$ cat sshfile This is a test
So I *can* write to the ssh connection but the 'read' never returns.. it just hangs-- I just don't know how to get read and write to play nice together.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing to an SSH channel
by salva (Canon) on Sep 19, 2018 at 07:26 UTC | |
|
Re: Writing to an SSH channel
by Marshall (Canon) on Sep 18, 2018 at 20:23 UTC | |
by BernieC (Pilgrim) on Sep 18, 2018 at 23:51 UTC | |
by Marshall (Canon) on Sep 19, 2018 at 00:16 UTC |