Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 80 lines (61 sloc) 1.885 kb
0a49745 Rocco Caputo eg/Runner.pm works with other open3()-like things. Very nice!
authored
1 #!/usr/bin/perl
2 # vim: ts=2 sw=2 noexpandtab
3
4 # Demonstrate Runner.pm used with other open3-like things.
5
6 use warnings;
7 use strict;
8 use lib qw(../lib);
9
10 use Runner;
11
12 my $cmd = q(
13 perl -MTime::HiRes=sleep -wle '
14 $| = 1;
15 for (1..3) { $_ = qq[pid($$) moo($_)]; print; warn "$_\n"; sleep rand; }
16 '
17 );
18
19 sub my_start {
20 my ($host, $cmd) = @_;
21
22 use Net::SSH qw(sshopen3);
23 use Symbol qw(gensym);
24
25 my ($fh_in, $fh_out, $fh_err) = (gensym(), gensym(), gensym());
26
27 my $pid = sshopen3($host, $fh_in, $fh_out, $fh_err, $cmd);
28
29 return($pid, $fh_in, $fh_out, $fh_err);
30 }
31
32 my $runner_1;
33 {
34 my ($pid, $fh_in, $fh_out, $fh_err) = my_start('remote.example.com', $cmd);
35
36 $runner_1 = Runner->new(
37 stdin => $fh_in,
38 stdout => $fh_out,
39 stderr => $fh_err,
40 pid => $pid,
41
42 on_stdout_closed => sub { print "runner_1 stdout closed\n" },
43 on_stderr_closed => sub { print "runner_1 stderr closed\n" },
5c57d49 Rocco Caputo !!! Experiment with Reflex events being objects.
authored
44 on_stdout_data => sub { print "runner_1 stdout: ", $_[1]->octets() },
45 on_stderr_data => sub { print "runner_1 stderr: ", $_[1]->octets() },
0a49745 Rocco Caputo eg/Runner.pm works with other open3()-like things. Very nice!
authored
46
47 on_exit => sub {
5c57d49 Rocco Caputo !!! Experiment with Reflex events being objects.
authored
48 my ($self, $child) = @_;
49 warn "runner_1 child ", $child->pid(), " exited: ", $child->exit(), "\n";
0a49745 Rocco Caputo eg/Runner.pm works with other open3()-like things. Very nice!
authored
50 $runner_1 = undef;
51 },
52 );
53 }
54
55 my $runner_2;
56 {
57 my ($pid, $fh_in, $fh_out, $fh_err) = my_start('remote.example.com', $cmd);
58
59 $runner_2 = Runner->new(
60 stdin => $fh_in,
61 stdout => $fh_out,
62 stderr => $fh_err,
63 pid => $pid,
64
65 on_stdout_closed => sub { print "runner_2 stdout closed\n" },
66 on_stderr_closed => sub { print "runner_2 stderr closed\n" },
5c57d49 Rocco Caputo !!! Experiment with Reflex events being objects.
authored
67 on_stdout_data => sub { print "runner_2 stdout: ", $_[1]->octets() },
68 on_stderr_data => sub { print "runner_2 stderr: ", $_[1]->octets() },
0a49745 Rocco Caputo eg/Runner.pm works with other open3()-like things. Very nice!
authored
69
70 on_exit => sub {
5c57d49 Rocco Caputo !!! Experiment with Reflex events being objects.
authored
71 my ($self, $child) = @_;
72 warn "runner_2 child ", $child->pid(), " exited: ", $child->exit(), "\n";
0a49745 Rocco Caputo eg/Runner.pm works with other open3()-like things. Very nice!
authored
73 $runner_2 = undef;
74 },
75 );
76 }
77
78 Reflex->run_all();
79 exit;
Something went wrong with that request. Please try again.