Proc::SafeExec

Convenient utility for executing external commands in various ways.
Download

Proc::SafeExec Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Leif Pedersen
  • Publisher web site:
  • http://search.cpan.org/~bilbo/

Proc::SafeExec Tags


Proc::SafeExec Description

Convenient utility for executing external commands in various ways. Proc::SafeExec is a convenient utility for executing external commands in various ways.SYNOPSIS use Proc::SafeExec; my $command = new Proc::SafeExec({ # Choose just one of these. exec => , # exec() after forking. fork => 1, # Return undef in the child after forking. # Specify whether to capture each. Specify a file handle ref to dup an # existing one. Specify "new" to create a new file handle, "default" or undef # to keep the parent's descriptor, or "close" to close it. stdin => *INPUT_PIPE, stdout => *OUTPUT_PIPE, stderr => "new", # Miscellaneous options. child_callback => &fref, # Specify a function to call in the child after fork(), for example, to drop privileges. debug => 1, # Emit some information via warnings, such as the command to execute. no_autowait => 1, # Don't automatically call $command->wait() when $command is destroyed. real_arg0 => "/bin/ls", # Specify the actual file to execute. untaint_args => 1, # Untaint the arguments before exec'ing. }); printf "Child's PID is %s ", $command->child_pid() if $command->child_pid();The wait method waits for the child to exit or checks whether it already exited: $command->wait({ # Optional hash of options. no_close => 1, # Don't close "new" file handles. nonblock => 1, # Don't wait if the child hasn't exited (implies no_close). });To communicate with the child: # Perl doesn't understand < $command->stdout() >. my $command_stdout = $command->stdout(); my $command_stderr = $command->stderr(); $line = < $command_stdout >; $line = < $command_stderr >; print {$command->stdin()} "mumble ";To check whether the child exited yet: print "Exit status: ", $command->exit_status(), " " if $command->wait({nonblock => 1});To wait until it exits: $command->wait(); print "Exit status: ", $command->exit_status(), " ";A convenient quick tool for an alternative to $output = `@exec`: ($output, $?) = Proc::SafeExec::backtick(@exec); Requirements: · Perl


Proc::SafeExec Related Software