IPC::Run

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

IPC::Run Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Barrie Slaymaker
  • Publisher web site:
  • http://search.cpan.org/~rbs/

IPC::Run Tags


IPC::Run Description

IPC::Run is a Perl module for system() and background procs w/ piping, redirs, ptys (Unix, Win32). IPC::Run is a Perl module for system() and background procs w/ piping, redirs, ptys (Unix, Win32).Requirements:· PerlSYNOPSIS ## 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


IPC::Run Related Software