-
-
Save TristinDavis/4098749 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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