Command::Runner(3pm)
π Command::Runner π (the Perl one, bestie)
okay so picture this: you're in Perl land, and you need to run stuff. External commands? Perl code refs? Both?? This module has you covered, no cap. It's Command::Runner, and it's giving main character energy for process-running. π¦
β¨ SYNOPSIS β¨
like, here's the whole vibe in one go:
use Command::Runner;
my $cmd = Command::Runner->new(
command => ['ls', '-al'],
timeout => 10,
stdout => sub { warn "out: $_[0]\n" },
stderr => sub { warn "err: $_[0]\n" },
);
my $res = $cmd->run;
periodt. that's the whole flex. π
πΈ DESCRIPTION πΈ
Command::Runner runs external commands and Perl code refs. that's it, that's the tweet. literally both. obsessed. π
π METHODS π
new
the constructor, bestie. it takes a whole little stack of options and honestly? each one ate:
commandβ an array of external commands, a string of external programs, or a Perl code ref. and lowkey important: if you pass an array of external commands, it gets automatically quoted on Windows. πͺβ¨timeoutβ timeout in seconds. and yes you can set a float second, go off with your0.5s. β±οΈredirectβ if this is true, stderr redirects to stdout. two streams, one vibe. πkeepβ by default, even if stdout/stderr is consumed, it is preserved for the return value. you can disable this behavior by setting thekeepoption false. so like, keep your receipts unless you say otherwise. π§Ύstdout/stderrβ a code ref that will be called whenever stdout/stderr is available. little callbacks popping off whenever there's tea to spill. βenvβ set environment variables, bestie.
Command::Runner->new(..., env => \%env)->run
is roughly equivalent to
{
local %ENV = %env;
Command::Runner->new(...)->run;
}
cwdβ set the current directory. where we're living today. π
Command::Runner->new(..., cwd => $dir)->run
is roughly equivalent to
{
require File::pushd;
my $guard = File::pushd::pushd($dir);
Command::Runner->new(...)->run;
}
run
run the command, obviously. π¨ it returns a hash reference, and inside that hash ref you get:
resulttimeoutstdoutstderrpid
five little keys, all iconic, all yours. π
π₯ MOTIVATION π₯
storytime fr fr: the author develops a CPAN client called App::cpm, and needed to execute external commands and Perl code refs with:
timeoutquoting- flexible logging
and while App::cpanminus has excellent APIs for such use, they still needed to tweak them in App::cpm. so instead of fighting it, they ended up creating a seperate module, Command::Runner. and honestly? slay. a whole module born from necessity. πβ
π AUTHOR π
Shoichi Kaji <skaji@cpan.org>
π COPYRIGHT AND LICENSE π
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.
okay that's the whole page, bestie, go run some commands π«Ά this masterpiece is perl v5.40.2, dated 2025-04-28, and it's the Command::Runner(3pm) manual β drink water and read your docs πβ¨
π¦ where this page comes from
- epel 10: perl-Command-Runner 0.201-1.el10_1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms