Last active
April 14, 2016 09:15
-
-
Save tadegenban/9029ab8ffcb47079ead5df4630749956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use feature 'say'; | |
use Mojo::IOLoop::ReadWriteFork; | |
sub myfork { | |
my $fork = Mojo::IOLoop::ReadWriteFork->new( ioloop => Mojo::IOLoop->singleton); | |
my $cat_result = ''; | |
$fork->on(error => sub { | |
my($fork, $error) = @_; | |
warn $error; | |
}); | |
$fork->on(close => sub { | |
my($fork, $exit_value, $signal) = @_; | |
warn "got close event"; | |
Mojo::IOLoop->stop; | |
}); | |
$fork->on(read => sub { | |
my($fork, $buffer) = @_; # $buffer = both STDERR and STDOUT | |
say $buffer; | |
$cat_result .= $buffer; | |
}); | |
$fork->run( sub { print $_[0] . "\n"; print '---' . "\n" ; print $_[1] . "\n"}, | |
'arg1', 'arg2' | |
); | |
} | |
myfork(); | |
Mojo::IOLoop->singleton->start; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment