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

Connector::Builtin::System::Exec

Description

Run a command using Proc::SafeExec.

Allows passing of arguments, stdin and env, each item of those lists is parsed as a template with the path arguments set in ARGS. In set mode the filename generated from content is set to FILE.

Usage

Configuration

my $con = Connector::Proxy::DBI->new({
    LOCATION => '/usr/bin/script',
    args     => ['--foo','ARGS.0'],
    content  => '[% payload %]',
    env => {
        BAR => 'bar'
    },
    chomp_output  => 1,
    timeout  => 2,
});

Parameters

args

List of parameters that are passed as arguments to the command.

timeout

Timeout to wait for the command in seconds, default is 5

chomp_output
stdin

A string or an array of strings to pipe as stdin to the command. Items are joined with a newline.

env

Expects a HashRef where the key is the name of the ENV variable.

content

A template string used to generate a tempfile when set mode is used.

The following call will create a tempfile with the content 'Hello World' and afterwards runs the systems copy command using the first path argument from the connector call as target filename.

my $con = Connector::Proxy::DBI->new({
    LOCATION => '/usr/bin/cp',
    args     => ['[% FILE %]', '[% ARGS.0 %]''],
    content  => '[% payload %]',
});
$conn->set('foo.txt', { payload => 'Hello World' } );