GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Command::Runner(3) User Contributed Perl Documentation Command::Runner(3)

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

  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;

Command::Runner runs external commands and Perl code refs

A constructor, which takes:

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.
timeout second. You can set float second.
if this is true, stderr redirects to stdout
by default, even if stdout/stderr is consumed, it is preserved for return value. You can disable this behavior by setting keep option false.
stdout / stderr
a code ref that will be called whenever stdout/stderr is available
set environment variables.

  Command::Runner->new(..., env => \%env)->run
    

is roughly equivalent to

  {
    local %ENV = %env;
    Command::Runner->new(...)->run;
  }
    
set the current directory.

  Command::Runner->new(..., cwd => $dir)->run
    

is roughly equivalent to

  {
    require File::pushd;
    my $guard = File::pushd::pushd($dir);
    Command::Runner->new(...)->run;
  }
    

Run command. It returns a hash reference, which contains:

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.

2022-03-21 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.