.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.48) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Command::Runner 3pm" .TH Command::Runner 3pm 2026-10-26 "perl v5.44.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Command::Runner \- run external commands and Perl code refs .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Command::Runner; \& \& my $cmd = Command::Runner\->new( \& command => [\*(Aqls\*(Aq, \*(Aq\-al\*(Aq], \& timeout => 10, \& stdout => sub ($line) { warn "out: $line\en" }, \& stderr => sub ($line) { warn "err: $line\en" }, \& ); \& my $res = $cmd\->run; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Command::Runner runs external commands and Perl code refs .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" A constructor, which takes: .IP command 4 .IX Item "command" an array of external commands, a string of external programs, or a Perl code ref. If an array of external commands is specified, it is automatically quoted on Windows. .IP timeout 4 .IX Item "timeout" timeout second. You can set float second. .IP redirect 4 .IX Item "redirect" if this is true, stderr redirects to stdout .IP keep 4 .IX Item "keep" by default, even if stdout/stderr is consumed, it is preserved for return value. You can disable this behavior by setting keep option false. .IP "stdout / stderr" 4 .IX Item "stdout / stderr" a code ref that will be called whenever stdout/stderr is available .IP env 4 .IX Item "env" set environment variables. .Sp .Vb 1 \& Command::Runner\->new(..., env => \e%env)\->run .Ve .Sp is roughly equivalent to .Sp .Vb 4 \& { \& local %ENV = %env; \& Command::Runner\->new(...)\->run; \& } .Ve .IP cwd 4 .IX Item "cwd" set the current directory. .Sp .Vb 1 \& Command::Runner\->new(..., cwd => $dir)\->run .Ve .Sp is roughly equivalent to .Sp .Vb 5 \& { \& require File::pushd; \& my $guard = File::pushd::pushd($dir); \& Command::Runner\->new(...)\->run; \& } .Ve .SS run .IX Subsection "run" Run command. It returns a hash reference, which contains: .IP result 4 .IX Item "result" .PD 0 .IP timeout 4 .IX Item "timeout" .IP stdout 4 .IX Item "stdout" .IP stderr 4 .IX Item "stderr" .IP pid 4 .IX Item "pid" .PD .SH MOTIVATION .IX Header "MOTIVATION" I develop a CPAN client App::cpm, where I need to execute external commands and Perl code refs with: .IP timeout 4 .IX Item "timeout" .PD 0 .IP quoting 4 .IX Item "quoting" .IP "flexible logging" 4 .IX Item "flexible logging" .PD .PP While App::cpanminus has excellent APIs for such use, I still needed to tweak them in App::cpm. .PP So I ended up creating a seperate module, Command::Runner. .SH "ARTIFACT ATTESTATIONS" .IX Header "ARTIFACT ATTESTATIONS" GitHub Artifact Attestations are generated for release tarballs uploaded to CPAN. If you care about provenance for the uploaded tarballs, see: .PP .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2017 Shoichi Kaji .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.