in reply to Re^2: Net SSH problems
in thread Net SSH problems

Here is how you can do it, the key is send_eof():

use Net::SSH2; use strict; my $ssh = Net::SSH2->new(); $ssh->connect("curry") or die "Unable to connect host\n"; $ssh->auth_password("aabchts4", "doneit") or die "Failed to auth\n"; my $channel = $ssh->channel() or die "Channel creation failed\n"; $channel->exec("wc"); $channel->write("abc def\n"); $channel->write("abc def\n"); $channel->send_eof(); while (<$channel>) {print;}

Peter (Guo) Pei

Replies are listed 'Best First'.
Re^4: Net SSH problems
by perlinmyveins (Novice) on Nov 15, 2010 at 10:09 UTC
    Ho ho ho! That certainly has the ring of truth about it. How careless of me to miss that!! I'll check it out. Thank you very much for spending your precious time helping me fix my problem!!
Re^4: Net SSH problems
by perlinmyveins (Novice) on Nov 15, 2010 at 11:38 UTC
    Right, I tried this, and although obviously necessary, (I am after all swapping from write to read on an object that is something like a file handle.) sending an EOF after finishing the data write did not solve all the problems. At first it worked exactly as expected, then I increased the size of the data sent to 100k and this is what I got:
    ssh created ssh connected ssh authenticated cmd is wc intext length is 100000 0 1 32768 remote exit status is 0 bytes returned is 24 bytes
    Note that intext length is measured at the local machine, and the numbers come from wc at the remote end - it only got 32k. 24 bytes returned looks correct.

    It WAS necessary to set blocking(1) (presumably the default would have been ok) , without this NO input at all was received by wc, but the process still ran and returned output , 0 0 0 in that case.

    I tried this to another Ubuntu box with exactly the same results.

    So Net::SSH2 still seems broken, but now in a way that is very similar to the way Net::SSH::Perl is broken.

    Hmmm.