Cmd - easy way to do piped opening of a command.
Cmd is designed to be an easy way to fork a shell script or other program and process its output as the command runs.
A quick example:
#!/usr/bin/perl
use Cmd;
my $sh = new Cmd;
$sh->execute('bin/some_command -very_verbose');
while ( $out_line = $sh->result ) { ## Note: This won't put result into $_ by default!
# process the result
}
Cmd provides a way to process examine the output of a child shell WHILE IT IS RUNNING. This is desireable if the child script taks a long time to run and produces a lot of output. Using the backquote operator it is theoretically possible to exhaust all of memory before the child script terminates. Cmd provides a workaround.
fatal => a true value will cause die to be called if the command returns a non-zero exit code
log => a referance to a Log.pm object. Command results are logged at the 'info' level.
execute('cmd_string')Fork and execute the given command
result()This is where the command results are grabbed from the filehandle. Return the top of the result que if called in a scalar context. Return the whole result que if called in an array context. Return undefined if the command has terminated.
abort()Closes the filehandle to the command.
exit_status()Return the most recently executed command's exit status.
doit('cmd_string')Do the command without returning a result. Returns 1 if command exits with 0.
discard()Seek the end of the child's output buffer and resume processing there.
Tom Whipple <mail@tomwhipple.com>