Skip to content

Instantly share code, notes, and snippets.

@shibayu36
Created September 1, 2012 16:13
Show Gist options
  • Save shibayu36/3578958 to your computer and use it in GitHub Desktop.
Save shibayu36/3578958 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use POSIX;
use Net::OpenSSH;
use AnyEvent;
use AnyEvent::Handle;
my $conn = Net::OpenSSH->new(
'host.h', user => 'hoge',
);
my ($stdin, $stdout, $stderr, $pid) = $conn->open3("ls");
my $cv = AnyEvent->condvar;
my $fhout; $fhout = AnyEvent::Handle->new(
fh => $stdout,
on_read => sub {
$fhout->push_read(line => sub {
my ($handle, $line) = @_;
print sprintf "::: %s\n",
$line;
});
},
on_eof => sub {
undef $fhout;
$cv->send;
},
on_error => sub {
undef $fhout;
$cv->send;
},
);
$cv->recv;
waitpid($pid, 0);
warn $?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment