IPC::Run 0.80 review

Download
by rbytes.net on

IPC::Run is a Perl module for system() and background procs w/ piping, redirs, ptys (Unix, Win32). Requirements: · Perl SYNOPS

License: Perl Artistic License
File size: 87K
Developer: Barrie Slaymaker
0 stars award from rbytes.net

IPC::Run is a Perl module for system() and background procs w/ piping, redirs, ptys (Unix, Win32).

Requirements:
Perl

SYNOPSIS

## First,a command to run:
my @cat = qw( cat ) ;

## Using run() instead of system():
use IPC::Run qw( run timeout ) ;

run @cmd, $in, $out, $err, timeout( 10 ) or die "cat: $?"

# Can do I/O to sub refs and filenames, too:
run @cmd, '< ', "in.txt", &out, &err or die "cat: $?"
run @cat, '< ', "in.txt", '>>', "out.txt", '2>>', "err.txt" ;


# Redirecting using psuedo-terminals instad of pipes.
run @cat, '< pty< , $in, ' >pty >', $out_and_err ;

## Scripting subprocesses (like Expect):

use IPC::Run qw( start pump finish timeout ) ;

# Incrementally read from / write to scalars.
# $in is drained as it is fed to cat's stdin,
# $out accumulates cat's stdout
# $err accumulates cat's stderr
# $h is for "harness".
my $h = start @cat, $in, $out, $err, timeout( 10 ) ;

$in .= "some inputn" ;
pump $h until $out =~ /inputn/g ;

$in .= "some more inputn" ;
pump $h until $out =~ /G.*more inputn/ ;

$in .= "some final inputn" ;
finish $h or die "cat returned $?" ;

warn $err if $err ;
print $out ; ## All of cat's output

# Piping between children
run @cat, '|', @gzip ;

# Multiple children simultaneously (run() blocks until all
# children exit, use start() for background execution):
run @foo1, '&', @foo2 ;

# Calling &set_up_child in the child before it executes the
# command (only works on systems with true fork() & exec())
# exceptions thrown in set_up_child() will be propagated back
# to the parent and thrown from run().
run @cat, $in, $out,
init => &set_up_child ;

# Read from / write to file handles you open and close
open IN, '< in.txt' or die $! ;
open OUT, '>out.txt' or die $! ;
print OUT "preamblen" ;
run @cat, *IN, *OUT or die "cat returned $?" ;
print OUT "postamblen" ;
close IN ;
close OUT ;

# Create pipes for you to read / write (like IPC::Open2 & 3).
$h = start
@cat,
'< pipe', *IN,
'>pipe', *OUT,
'2>pipe', *ERR
or die "cat returned $?" ;
print IN "some inputn" ;
close IN ;
print < OUT >, < ERR > ;
finish $h ;

# Mixing input and output modes
run @cat, 'in.txt', &catch_some_out, *ERR_LOG ) ;

# Other redirection constructs
run @cat, '>&', $out_and_err ;
run @cat, '2>&1' ;
run @cat, '0 1 ;

# Call this system's shell, returns TRUE on 0 exit code
# THIS IS THE OPPOSITE SENSE OF system()'s RETURN VALUE
run "cat a b c" or die "cat returned $?" ;

# Launch a sub process directly, no shell. Can't do redirection
# with this form, it's here to behave like system() with an
# inverted result.
$r = run "cat a b c" ;

# Read from a file in to a scalar
run io( "filename", 'r', $recv ) ;
run io( *HANDLE, 'r', $recv ) ;

Requirements:
Perl

IPC::Run 0.80 keywords