Skip to content

Instantly share code, notes, and snippets.

@kraih
Created April 7, 2012 03:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kraih/2324894 to your computer and use it in GitHub Desktop.
Save kraih/2324894 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
use EV;
use IO::Async::Process;
use IO::Async::Loop::EV;
my $loop = IO::Async::Loop::EV->new;
get '/' => sub {
my $self = shift;
# Run Perl oneliner in separate process and capture STDOUT
my $result = '';
my $process = IO::Async::Process->new(
command => ['perl', '-E', "say 'hi!'"],
stdout => {
on_read => sub {
my ($stream, $buffref) = @_;
$result .= $1 while $$buffref =~ s/^(.*)\n//;
return 0;
},
},
on_finish => sub { $self->render(text => "Result: $result") },
);
$loop->add($process);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment