ePages 6.17.15 - DE_EPAGES/Core/API/SystemCommand.pm

Package DE_EPAGES::Core::API::SystemCommand

This Module starts an external process.

@EXPORT_OK
SystemCommand
RunCommandsInDir
UnpackTar
PackTar

Functions

PackTar
RunCommandsInDir
SystemCommand
UnpackTar

PackTar

Pack $aFiles (files/dirs/globs) from $Directory into $Package (.tar/.tar.gz/.tgz)

Syntax
$aPackedFiles = PackTar($Package, $Directory, $aFiles, $hFlags);
Example
PackTar($Package); # pack '*' (in cwd()) into $Package
PackTar($Package, $Directory); # chdir $Directory and pack '*' into $Package
PackTar($Package, undef, ['a*']); # pack files starting with 'a' into $Package
Input
$Package (string)
path to .tar/.tar.gz/.tgz package
$Directory (string)
put files from $Directory into $Package (default: '.')
$aFiles (ref.array)
put $aFiles (files/dirs/globs) into $Package (default: ['*'])
beware: '*' does not include files starting with '.'!
$hFlags (ref.hash)
(optional) keys are:
  • Print - print the command line before execution - boolean
  • Warning - does not thow an error but a warning

Return
$aPackedFiles (ref.array)
array of files in package

RunCommandsInDir

Execute files ending in *.sh, *.cmd or *.bat in $Dir with $Args

Syntax
$Status = RunCommandsInDir($Dir, $Args, $Output)
Input
$Dir (string)
directory containing files
$Args (ref.array)
additional arguments for SystemCommand()
$Output (ref.string)
write output into string
Return
$Status (integer)
0 - success ; else - failue

SystemCommand

Executes a system command and throws an error if the command does not terminate with exit code 0. Possible error codes are:

Syntax
SystemCommand( $CommandLine, $hOptions );
SystemCommand( $aCommandLine, $hOptions );
$Output = SystemCommand( $CommandLine, $hOptions );
Example
SystemCommand( ['java', '-version'], { 'Print' => 1 });
$Output = SystemCommand( "perl -v", { 'Capture' => 1 });
Input
$CommandLine (string)
command with paramters
$aCommandLine (ref.array)
command with paramters, first array element is the executable
$hOptions (ref.hash)
(optional) keys are:
  • Print - print the command line before execution - boolean
  • Capture - captures STDOUT and returns it as string
  • Warning - does not thow an error but a warning

Return
$Output (string)
command output (from STDOUT), only if Capture is true

UnpackTar

Unpack $Package (.tar/.tar.gz/.tgz) into $Directory (default: cwd()).

Syntax
$aPackedFiles = UnpackTar($Package, $Directory, $hFlags);
Example
$aPackedFiles = UnpackTar($Package); # unpack into cwd()
SetAccessRights($_) foreach @$aPackedFiles; # and set access rights
# beware: if the package only contains files, missing dirs are created
# automatically and access rights for this dirs must be  set as well!
$aPackedFiles = UnpackTar($Package, $Directory); # unpack into $Directory
Input
$Package (string)
path to .tar/.tar.gz/.tgz package
$Directory (string)
put $Package files into $Directory (default: .)
$hFlags (ref.hash)
(optional) keys are:
  • Print - print the command line before execution - boolean
  • Warning - does not thow an error but a warning

Return
$aPackedFiles (ref.array)
array of files in package