The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

VcsTools::Process - Perl functions to handle child process (blocking mode)

SYNOPSIS

 my $res = openPipe 
  (
   command => 'll',
   trace => $trace
  ) ;

 $res = pipeIn (command => 'bc',
               trace => $trace,
               input => "3+4+2\nquit\n"
              );

 $res = mySystem
   (
    command => 'echo >/dev/console',
    trace => $trace,
   );

DESCRIPTION

This package provides functions which are the standard perl functions (system, open, and open2) with some sugar coating to avoid duplicated code.

Common parameters

The functions mySystem, openPipe and pipeIn accepts these parameters:

  • command: the command to run

  • trace: If set to 1, the command will be printed on STDERR before execution.

  • expect: hash ref specifying how the process exit code must be interpreted. Defaults to ( 0 => 1, 255 => 0 ).

  • workDir: where to run the command (defaults to the current directory). If specified all functions will perform a chdir to 'workDir' before executing the command and will chdir back before returning.

Error checking

In case of errors all functions returns undef. In this case you can get the error cause by calling the getError function.

Functions

mySystem(...)

Will run a system() call. Returns 1 in case of succes, undef in case of problems.

openPipe(...)

Will open a pipe on command and read its STDOUT. Returns an array ref in case of succes, undef in case of problems.

The array will contain chomped lines of the STDOUT of the command.

pipeIn(...)

Will open a pipe on the STDIN and STDOUT of command (see open2), send the content of the 'input' parameter to the process and read its STDOUT.

Returns an array ref in case of succes, undef in case of problems.

The array will contain chomped lines of the STDOUT of the command.

Parameters are:

  • input: string to send to the command

getError()

Return a string containing the error message of the last command which had some problem. It works a bit like the errno variable.

AUTHOR

Dominique Dumont, Dominique_Dumont@grenoble.hp.com

Copyright (c) 1998-1999 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1)