Command::Runner(3pm)

πŸ“¦
version 0.201 Β· 5 versions
, in epel 10

πŸ’– 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 your 0.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 the keep option 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:

  • result
  • timeout
  • stdout
  • stderr
  • pid

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:

  • timeout
  • quoting
  • 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 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