1Command::Runner(3pm)  User Contributed Perl Documentation Command::Runner(3pm)
2
3
4

NAME

6       Command::Runner - run external commands and Perl code refs
7

SYNOPSIS

9         use Command::Runner;
10
11         my $cmd = Command::Runner->new(
12           command => ['ls', '-al'],
13           timeout => 10,
14           stdout  => sub { warn "out: $_[0]\n" },
15           stderr  => sub { warn "err: $_[0]\n" },
16         );
17         my $res = $cmd->run;
18
19         my $untar = Command::Runner->new;
20         $untar->commandf(
21           '%q -dc %q | %q tf -',
22           'C:\\Program Files (x86)\\GnuWin32\\bin\\gzip.EXE',
23           'File-ShareDir-Install-0.13.tar.gz'
24           'C:\\Program Files (x86)\\GnuWin32\\bin\\tar.EXE',
25         );
26         my $capture = $untar->run->{stdout};
27

DESCRIPTION

29       Command::Runner runs external commands and Perl code refs
30

METHODS

32   new
33       A constructor, which takes:
34
35       command
36           an array of external commands, a string of external programs, or a
37           Perl code ref.  If an array of external commands is specified, it
38           is automatically quoted on Windows.
39
40       commandf
41           a command string by "sprintf"-like syntax.  You can use positional
42           formatting together with a conversion %q (with quoting).
43
44           Here is an example:
45
46             my $cmd = Command::Runner->new(
47               commandf => [ '%q %q >> %q', '/path/to/cat', 'foo bar.txt', 'out.txt' ],
48             );
49
50             # or, you can set it separately
51             my $cmd = Command::Runner->new;
52             $cmd->commandf('%q %q >> %q', '/path/to/cat', 'foo bar.txt', 'out.txt');
53
54       timeout
55           timeout second. You can set float second.
56
57       redirect
58           if this is true, stderr redirects to stdout
59
60       keep
61           by default, even if stdout/stderr is consumed, it is preserved for
62           return value.  You can disable this behavior by setting keep option
63           false.
64
65       stdout / stderr
66           a code ref that will be called whenever stdout/stderr is available
67
68   run
69       Run command. It returns a hash reference, which contains:
70
71       result
72       timeout
73       stdout
74       stderr
75       pid
76

MOTIVATION

78       I develop a CPAN client App::cpm, where I need to execute external
79       commands and Perl code refs with:
80
81       timeout
82       quoting
83       flexible logging
84
85       While App::cpanminus has excellent APIs for such use, I still needed to
86       tweak them in App::cpm.
87
88       So I ended up creating a seperate module, Command::Runner.
89

AUTHOR

91       Shoichi Kaji <skaji@cpan.org>
92
94       Copyright 2017 Shoichi Kaji <skaji@cpan.org>
95
96       This library is free software; you can redistribute it and/or modify it
97       under the same terms as Perl itself.
98
99
100
101perl v5.28.0                      2018-05-02              Command::Runner(3pm)
Impressum