Command::Runner - run external commands and Perl code refs
use Command::Runner; my $cmd = Command::Runner->new( command => ['ls', '-al'], timeout => 10, on => { stdout => sub { warn "out: $_[0]\n" }, stderr => sub { warn "err: $_[0]\n" }, }, ); my ($status, $is_timeout) = $cmd->run; # you can also use method chains my $ret = Command::Runner->new ->command(sub { warn 1; print 2 }) ->redirect(1) ->on(stdout => sub { warn "merged: $_[0]" }) ->run;
Command::Runner runs external commands and Perl code refs
A constructor, which takes:
arrays of external commands, strings of external programs, or Perl code refs
CAUTION! Currently this module does NOTHING for quoting. YOU are responsible to quote argument lists. See Win32::ShellQuote and String::ShellQuote.
timeout second. You can set float second.
if this is true, stderr redirects to stdout
code refs that will be called whenever stdout/stderr is available
Run command. It returns ($status, $is_timeout) in list context, and $status in scalar context.
($status, $is_timeout)
$status
I develop a CPAN client App::cpm, where I need to execute external commands and Perl code refs with:
While App::cpanminus has excellent APIs for such use, I still needed to tweak them in App::cpm.
So I ended up creating a seperate module, Command::Runner.
Shoichi Kaji <skaji@cpan.org>
Copyright 2017 Shoichi Kaji <skaji@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Command::Runner, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Command::Runner
CPAN shell
perl -MCPAN -e shell install Command::Runner
For more information on module installation, please visit the detailed CPAN module installation guide.