Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Net::SSH2 related query

by keszler (Priest)
on Nov 19, 2013 at 14:21 UTC ( #1063338=note: print w/replies, xml ) Need Help??

in reply to Net::SSH2 related query

... print $chan "ls\n"; my @response = (readline $chan);

Replies are listed 'Best First'.
Re^2: Net::SSH2 related query
by nithins (Sexton) on Nov 20, 2013 at 06:26 UTC

    I used your code , but the print statement didn't print results of "ls command". however when i run the script in debugg mode i found "@respose" having results of "ls"

      Just tried again to reproduce your error. First, I am getting the same result (nothing read), if I set the timeout in the select-function too low, say
      #select(undef,undef,undef,0.2); select(undef,undef,undef,0.001);
      Maybe You should try a higher one?

      Second, it seems, that readline (or <>) is always able to read from the channel (no select necessary). The below code works for me. For you too?

      my $chan = $ssh->channel() or die "create channel:$!\n"; $chan->shell() or die("open shell: $!\n"); $chan->blocking(0); $chan->write("ls\n") or die("write to channel: $!\n"); while ( <$chan> + ) { print $_; }

      In print $chan "ls\n";, $chan is like a filehandle (open FH, '>', 'file.txt'; print FH "something\n";). The print command sends the characters over the SSH connection to the shell on the other end.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063338]
[LanX]: oh they have sleper cells everywhere
[robby_dobby]: LanX: Not really, the only problems would be from religious divides. Coptics/Moslems/ Kurds/Jews
[erix]: Zzz
[erix]: Coptics? :)
[robby_dobby]: erix: Coptic Christians in Egypt
[choroba]: Robocoptic!
[erix]: I like Coptics :)
[LanX]: Copts
[erix]: sorry - just pulling your leg
[robby_dobby]: erix: It's a little late for that :-)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (17)
As of 2017-04-24 16:10 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.