|
NAMEIPC::ShellCmd - Run a command with a given environment and capture outputSYNOPSISmy $isc = IPC::ShellCmd->new(["perl", "Makefile.PL"]) ->working_dir("/path/to/IPC_ShellCmd-0.01") ->stdin(-filename => "/dev/null") ->add_envs(PERL5LIB => "/home/mbm/cpanlib/lib/perl5") ->add_timers(300 => 'TERM', 360 => 'KILL', 5 => \&display_progress), ->chain_prog( IPC::ShellCmd::Sudo->new( User => 'cpanbuild', SetHome => 1, ) )->run(); my $stdout = $isc->stdout(); my $status = $isc->status(); DESCRIPTIONThis module comes from the nth time I've had to implement a select loop and wanted appropriate sudo/su privilege magic, environment variables that are set in the child, working directories set etc.It aims to provide a reasonable interface for setting up command execution environment (working directory, environment variables, stdin, stdout and stderr redirection if necessary), but allowing for ssh and sudo and magicking in the appropriate shell quoting. It tries to be flexible about how you might want to capture output, exit status and other such, but in such a way as it's hopefully easy to understand and make it work. Setup method calls are chain-able in a File::Find::Rule kind of a way. my $isc = IPC::ShellCmd->new(\@cmd, %opts)Creates a new IPC::ShellCmd object linking to the command and arguments. Possible options:
$isc->set_umask($mask)Sets the umask that this command is going to have, and returns so that it can be chained.$isc->working_dir([$path])Sets the working directory that this command is going to run under, and returns $isc so that it can be chained, or returns the current setting with no arguments.$isc->add_envs($env1 => $val1 [, $env2 => $val2, ...])Adds environment variables to be setup when the command is run. Returns $isc so that it can be chained.$isc->add_timers($time1 => $signame [, $time2 => \&handler, ...])Adds timers to be setup when the command is run. Returns $isc so that it can be chained.$isc->chain_prog($chain_obj, [$opt => $val, ...])Adds a chain object, for example IPC::ShellCmd::Sudo->new(User => 'root') into the chain. Returns $isc so that it can be chained.Valid options are:
$isc->stdin($stdin)$isc->stdin($type, $stdin)The 1 argument form takes either
The 2 argument form takes a type and then a ref, handle or other. Valid types:
Both of these return $isc for chaining. The default is an empty scalar. $isc->stdout()$isc->stderr()These 0-argument forms return the captured stdout/stderr if the default stdout/stderr handler is set and run() has been called. If either has been setup elsewhere, then these will croak() an error.$isc->stdout($value)$isc->stderr($value)$isc->stdout($type, $value)$isc->stderr($type, $value)These setup stdout/stderr as appropriate. The forms are similar to the stdin method above.The 1 argument form takes either
The 2 argument form takes a type and then a ref, handle or other. Valid types:
All of these forms return $isc for chaining. The default is that it will populate an internal variable to be used by the corresponding 0-argument form. $isc->status()Returns the exit status of the command if it got run.$isc->run()Runs the command with all the setup that has been done.BUGSApart from the ones that are probably in there and that I don't know about, this is a very UNIX-centric view of the world, it really should cope with Win32 concepts etc.SEE ALSOIPC::ShellCmd::Generic, IPC::ShellCmd::Sudo, IPC::ShellCmd::SSH, IO::Select, IPC::Open3AUTHORSMatthew Byng-Maddick <matthew.byng-maddick@bbc.co.uk> <mbm@colondot.net> Tomas Doran (t0m) <bobtfish@bobtfish.net> Andrew Ford <andrew@ford-mason.co.uk> COPYRIGHTCopyright (c) 2009 the British Broadcasting Corporation.LICENSEThis library is free software and may be distributed under the same terms as perl itself.
Visit the GSP FreeBSD Man Page Interface. |