SysTutorials

Linux Manual Pages › Section 3

lintiancommand(3)

Lintian::Command – Utilities to execute other commands from lintian code

Synopsis

 use Lintian::Command qw(spawn);
 # simplest possible call
 my $success = spawn({}, ['command']);
 # catch output
 my $opts = {};
 $success = spawn($opts, ['command']);
 if ($success) {
 print "STDOUT: $opts->{out}
";
 print "STDERR: $opts->{err}
";
 }
 # from file to file
 $opts = { in => 'infile.txt', out => 'outfile.txt' };
 $success = spawn($opts, ['command']);
 # piping
 $success = spawn({}, ['command'], "|", ['othercommand']);

Description

Lintian::Command is a thin wrapper around IPC::Run, that catches exception and implements a useful default behaviour for input and output redirection.

Lintian::Command provides a function spawn() which is a wrapper around IPC::Run::run() resp. IPC::Run::start() (depending on whether a pipe is requested). To wait for finished child processes, it also provides the reap() function as a wrapper around IPC::Run::finish().

spawn($opts, @cmds)

The @cmds array is given to IPC::Run::run() (or ::start()) unaltered, but should only be used for commands and piping symbols (i.e. all of the elements should be either an array reference, a code reference, ‘|’, or ‘&’). I/O redirection is handled via the $opts hash reference. If you need more fine grained control than that, you should just use IPC::Run directly.

$opts is a hash reference which can be used to set options and to retrieve the status and output of the command executed.

The following hash keys can be set to alter the behaviour of spawn():

in
STDIN for the first forked child. Defaults to "