Provided by: libsystem-command-perl_1.05-1_all bug


       System::Command - Object for running system commands


           use System::Command;

           # invoke an external command, and return an object
           $cmd = System::Command->new( @cmd );

           # options can be passed as a hashref
           $cmd = System::Command->new( @cmd, \%option );

           # $cmd is basically a hash, with keys / accessors
           $cmd->stdin();     # filehandle to the process' stdin (write)
           $cmd->stdout();    # filehandle to the process' stdout (read)
           $cmd->stderr();    # filehandle to the process' stdout (read)
           $cmd->pid();       # pid of the child process

           # find out if the child process died
           if ( $cmd->is_terminated() ) {
               # the handles are not closed yet
               # but $cmd->exit() et al. are available

           # done!

           # exit information
           $cmd->exit();      # exit status
           $cmd->signal();    # signal
           $cmd->core();      # core dumped? (boolean)

           # cut to the chase
           my ( $pid, $in, $out, $err ) = System::Command->spawn(@cmd);


       "System::Command" is a class that launches external system commands and return an object
       representing them, allowing to interact with them through their "STDIN", "STDOUT" and
       "STDERR" handles.


       "System::Command" supports the following methods:

   new( @cmd )
       Runs an external command using the list in @cmd.

       If @cmd contains a hash reference, it is taken as an option hash.

       The recognized keys are:

           The current working directory in which the command will be run.

           A hashref containing key / values to add to the command environment.

           If a value is "undef", the variable corresponding to the key will be removed from the

           A string that is send to the command's standard input, which is then closed.

           Using the empty string as "input" will close the command's standard input without
           writing to it.

           Using "undef" as "input" will not do anything. This behaviour provides a way to modify
           previous options populated by some other part of the program.

           On some systems, some commands may close standard input on startup, which will cause a
           SIGPIPE when trying to write to it. This will raise an exception.

       If several option hashes are passed to "new()", they will be merged together with
       individual values being overridden by those (with the same key) from hashes that appear
       later in the list.

       The "System::Command" object returned by "new()" has a number of attributes defined (see

       Close all pipes to the child process, collects exit status, etc.  and defines a number of
       attributes (see below).

       Returns a true value if the underlying process was terminated.

       If the process was indeed terminated, collects exit status, etc.  and defines the same
       attributes as "close()", but does not close all pipes to the child process,

   spawn( @cmd )
       This shortcut method calls "new()" (and so accepts options in the same manner) and
       directly returns the "pid", "stdin", "stdout" and "stderr" attributes, in that order.

       The attributes of a "System::Command" object are also accessible through a number of

       The object returned by "new()" will have the following attributes defined:

           Return the command-line actually executed, as a list of strings.

           The merged list of options used to run the command.

           The PID of the underlying command.

           A filehandle opened in write mode to the child process' standard input.

           A filehandle opened in read mode to the child process' standard output.

           A filehandle opened in read mode to the child process' standard error output.

       Regarding the handles to the child process, note that in the following code:

           my $fh = System::Command->new( @cmd )->stdout;

       $fh is opened and points to the output handle of the child process, while the anonymous
       "System::Command" object has been destroyed. Once $fh is destroyed, the subprocess will be
       reaped, thus avoiding zombies.

       After the call to "close()" or after "is_terminated()" returns true, the following
       attributes will be defined:

           The exit status of the underlying command.

           A boolean value indicating if the command dumped core.

           The signal, if any, that killed the command.


       Note that "System::Command" uses "waitpid()" to catch the status information of the child
       processes it starts. This means that if your code (or any module you "use") does something
       like the following:

           local $SIG{CHLD} = 'IGNORE';    # reap child processes

       "System::Command" will not be able to capture the "exit", "core" and "signal" attributes.
       It will instead set all of them to the impossible value "-1", and display the warning
       "Child process already reaped, check for a SIGCHLD handler".

       To silence this warning (and accept the impossible status information), load
       "System::Command" with:

           use System::Command -quiet;

       It is also possible to more finely control the warning by setting the
       $System::Command::QUIET variable (the warning is not emitted if the variable is set to a
       true value).

       If the subprocess started by "System::Command" has a short life expectancy, and no other
       child process is expected to die during that time, you could even disable the handler
       locally (use at your own risks):

               local $SIG{CHLD};
               my $cmd = System::Command->new(@cmd);


       Philippe Bruhat (BooK), "<book at>"


       Thanks to Alexis Sukrieh who, when he saw the description of "Git::Repository::Command"
       during my talk at 2010, asked why it was not an independent module. This module
       was started by taking out of "Git::Repository::Command" 1.08 the parts that weren't
       related to Git.


       Please report any bugs or feature requests to "bug-system-command at", or
       through the web interface at
       <>.  I will be notified, and
       then you'll automatically be notified of progress on your bug as I make changes.


       You can find documentation for this module with the perldoc command.

           perldoc System::Command

       You can also look for information at:

       ·   RT: CPAN's request tracker


       ·   AnnoCPAN: Annotated CPAN documentation


       ·   CPAN Ratings


       ·   Search CPAN



       Copyright 2010-2011 Philippe Bruhat (BooK).


       This program is free software; you can redistribute it and/or modify it under the terms of
       either: the GNU General Public License as published by the Free Software Foundation; or
       the Artistic License.

       See for more information.