Mojo::IOLoop::ReadWriteFork - Fork a process and read/write from it
0.18
This class enable you to fork a child process and "read" and "write" data to. You can also send signals to the child and see when the process ends.
Patches that enable the "read" event to see the difference between STDERR and STDOUT are more than welcome.
my $fork = Mojo::IOLoop::ReadWriteFork->new; my $cat_result = ""; # Emitted if something terrible happens $fork->on(error => sub { my ($fork, $error) = @_; warn $error; }); # Emitted when the child completes $fork->on(close => sub { my ($fork, $exit_value, $signal) = @_; Mojo::IOLoop->stop; }); # Emitted when the child prints to STDOUT or STDERR $fork->on(read => sub { my ($fork, $buf) = @_; print qq(Child process sent us "$buf"); }); # Need to set "conduit" for bash, ssh, and other programs that require a pty $fork->conduit("pty"); # Start the application $fork->run("bash", -c => q(echo $YIKES foo bar baz)]);
See https://github.com/jhthorsen/mojo-ioloop-readwritefork/tree/master/example/tail.pl.
$self->on(close => sub { my ($self, $exit_value, $signal) = @_; });
Emitted when the child process exit.
$self->on(error => sub { my ($self, $str) = @_; });
Emitted when when the there is an issue with creating, writing or reading from the child process.
$self->on(read => sub { my ($self, $chunk) = @_; });
Emitted when the child has written a chunk of data to STDOUT or STDERR.
$str = $self->conduit; $self = $self->conduit("pty");
Used to set the conduit. Can be either "pty" or "pipe" (default).
$ioloop = $self->ioloop; $self = $self->ioloop(Mojo::IOLoop->singleton);
Holds a Mojo::IOLoop object.
$int = $self->pid;
Holds the child process ID.
$self = $self->close("stdin");
Close STDIN stream to the child process immediately.
$self = $self->run($program, @program_args);
Simpler version of "start".
$self->start( program => $str, program_args => [@str], conduit => $str, # pipe or pty raw => $bool, clone_winsize_from => \*STDIN, );
Used to fork and exec a child process.
raw and clone_winsize_from|IO::Pty only makes sense if conduit is "pty".
clone_winsize_from|IO::Pty
conduit
$self = $self->write($chunk); $self = $self->write($chunk, $cb);
Used to write data to the child process STDIN. An optional callback will be called once STDIN is drained.
Example:
$self->write("some data\n", sub { my ($self) = @_; $self->close; });
$bool = $self->kill; $bool = $self->kill(15); # default
Used to signal the child.
Mojo::IOLoop::ForkCall.
Copyright (C) 2013-2016, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mojo::IOLoop::ReadWriteFork, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::IOLoop::ReadWriteFork
CPAN shell
perl -MCPAN -e shell install Mojo::IOLoop::ReadWriteFork
For more information on module installation, please visit the detailed CPAN module installation guide.