add options for backtick function

This commit is contained in:
Colin Gagnaire 2019-04-26 18:40:51 +02:00
parent 1dc9dd6e56
commit d64643e575
2 changed files with 24 additions and 17 deletions

View File

@ -119,6 +119,11 @@ sub unix_execute {
my $cmd = ''; my $cmd = '';
my $args = []; my $args = [];
my ($lerror, $stdout, $exit_code); my ($lerror, $stdout, $exit_code);
my $redirect_stderr = 1;
$redirect_stderr = $options{redirect_stderr} if (defined($options{redirect_stderr}));
my $wait_exit = 1;
$wait_exit = $options{wait_exit} if (defined($options{wait_exit}));
# Build command line # Build command line
# Can choose which command is done remotely (can filter and use local file) # Can choose which command is done remotely (can filter and use local file)
@ -149,19 +154,19 @@ sub unix_execute {
if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) { if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) {
$cmd = "echo '" . $sub_cmd . "' | " . $cmd . ' ' . join(" ", @$args); $cmd = "echo '" . $sub_cmd . "' | " . $cmd . ' ' . join(" ", @$args);
($lerror, $stdout, $exit_code) = backtick( ($lerror, $stdout, $exit_code) = backtick(
command => $cmd, command => $cmd,
timeout => $options{options}->{timeout}, timeout => $options{options}->{timeout},
wait_exit => 1, wait_exit => $wait_exit,
redirect_stderr => 1 redirect_stderr => $redirect_stderr
); );
} else { } else {
($lerror, $stdout, $exit_code) = backtick( ($lerror, $stdout, $exit_code) = backtick(
command => $cmd, command => $cmd,
arguments => [@$args, $sub_cmd], arguments => [@$args, $sub_cmd],
timeout => $options{options}->{timeout}, timeout => $options{options}->{timeout},
wait_exit => 1, wait_exit => $wait_exit,
redirect_stderr => 1 redirect_stderr => $redirect_stderr
); );
} }
} else { } else {
$cmd = 'sudo ' if (defined($options{sudo})); $cmd = 'sudo ' if (defined($options{sudo}));
@ -170,11 +175,11 @@ sub unix_execute {
$cmd .= $options{command_options} if (defined($options{command_options})); $cmd .= $options{command_options} if (defined($options{command_options}));
($lerror, $stdout, $exit_code) = backtick( ($lerror, $stdout, $exit_code) = backtick(
command => $cmd, command => $cmd,
timeout => $options{options}->{timeout}, timeout => $options{options}->{timeout},
wait_exit => 1, wait_exit => $wait_exit,
redirect_stderr => 1 redirect_stderr => $redirect_stderr
); );
} }
if (defined($options{options}->{show_output}) && if (defined($options{options}->{show_output}) &&

View File

@ -132,7 +132,9 @@ sub execute {
sudo => $self->{option_results}->{sudo}, sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command}, command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path}, command_path => $self->{option_results}->{command_path},
command_options => $options{cmd_options}); command_options => $options{cmd_options},
redirect_stderr => 0
);
my $raw_results; my $raw_results;