CPANPLUS::Tools::Cmd - finding and running system commands made easy |
CPANPLUS::Tools::Cmd - finding and running system commands made easy
use CPANPLUS::Tools::Cmd qw[can_run run];
my $full_path = can_run('wget') or warn 'wget is not installed!';
### commands can be arrayrefs or strings ### my $cmd = "$full_path -b theregister.co.uk"; my $cmd = [$full_path, '-b', 'theregister.co.uk'];
### in scalar context ### if( run(command => $cmd, verbose => 0) ) { print "fetched webpage succesfully\n"; }
### in list context ### my( $succes, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 );
if( $success ) { print "this is what the command printed:\n"; print join "", @$full_buf; }
### don't have CPANPLUS::Tools::Cmd be verbose, ie don't print to stdout or ### stderr when running commands -- default is '0' $CPANPLUS::Tools::Cmd::VERBOSE = 0;
CPANPLUS::Tools::Cmd allows you to run commands, interactively if desisered, platform independant but have them still work.
The can_run
function can tell you if a certain binary is installed
and if so where, whereas the run
function can actually execute any
of the commands you give it and give you a clear return value, as well
as adhere to your verbosity settings.
can_run
takes but a single argument: the name of a binary you wish
to locate. can_run
works much like the unix binary which
, which
scans through your path, looking for the binary you asked for.
Unlike which
however, this function is platform independant and
will also work on, for example, Win32.
It will return the full path to the binary you asked for if it was
found, or undef
if it was not.
run
takes 2 arguments:
IPC::Run
to be installed or your system able to work with
IPC::Open3
).
It will default to the global setting of $CPANPLUS::Tools::Cmd::VERBOSE
,
which by default is 0.
run
will return a simple true
or false
when called in scalar
context.
In list context, you will be returned a list of the following items:
IPC::Run
installed,
or if your system is able to work with IPC::Open3
-- See below).
This element will be undef
if this is not the case.
IPC::Run
installed,
or if your system is able to work with IPC::Open3
-- See below).
This element will be undef
if this is not the case.
IPC::Run
installed,
or if your system is able to work with IPC::Open3
-- See below).
This element will be undef
if this is not the case.
run
will try to execute your command using the following logic:
IPC::Run
installed, use that
to execute the command. You will have the full output available in
buffers, interactive commands are sure to work and you are guaranteed
to have your verbosity settings honored cleanly.
IPC::Open3
. Buffers will be available, interactive
commands will still execute cleanly, and also your verbosity settings
will be adhered to nicely;
system()
call. We can not capture any buffers, but
interactive commands will still work.
system()
call with your command and then re-open STDERR and STDOUT.
This is the method of last resort and will still allow you to execute
your commands cleanly. However, no buffers will be available.
The behaviour of CPANPLUS::Tools::Cmd can be altered by changing the following global variables:
This controls whether CPANPLUS::Tools::Cmd will print any output from the commands to the screen or not. The default is 0;
IPC::Run
, IPC::Open3
This module by Jos Boumans <kane@cpan.org>.
This module is copyright (c) 2002 Jos Boumans <kane@cpan.org>. All rights reserved.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
CPANPLUS::Tools::Cmd - finding and running system commands made easy |