diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-01-23 11:18:55 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-01-23 11:18:55 +0100 |
commit | 409de33c5739db45b896935c79eba40b68e106ec (patch) | |
tree | 9dafdde39556537eccdc778c4dc80e5cf3067efd /solenv/bin | |
parent | f2e6a55b803c4c7a200a4fbf8de342606d7d5939 (diff) |
In exectest.pl support commands prefixed by shell-style variable assignments
...and properly encode the command passed to Perl's open "|...", which in turn
apparently passes the command to the shell.
Change-Id: I19ab8f677dced6c1421fd9b4910d8a84743c1506
Diffstat (limited to 'solenv/bin')
-rw-r--r-- | solenv/bin/exectest.pl | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/solenv/bin/exectest.pl b/solenv/bin/exectest.pl index d504d6292904..06c9072d3ae3 100644 --- a/solenv/bin/exectest.pl +++ b/solenv/bin/exectest.pl @@ -16,6 +16,13 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # +sub encode($) +{ + my ($arg) = @_; + $arg =~ s/'/'\\''/g; + return $arg +} + $#ARGV >= 1 or die "Usage: $0 <input file>|-SUCCESS|-FAILURE <command> <arguments...>"; if ($ARGV[0] eq "-SUCCESS") @@ -78,7 +85,22 @@ while (1) { { undef $title; } - open PIPE, "| @ARGV" or die "cannot start process: $!"; + my $prog = ''; + my $assigns = 1; + for ($i = 0; $i != scalar(@ARGV); ++$i) + { + $prog .= ' ' unless $i == 0; + if ($assigns && $ARGV[$i] =~ /^([A-Za-z_][A-Za-z0-9_]+)=(.*)$/) + { + $prog .= $1 . "='" . encode($2) . "'"; + } + else + { + $prog .= "'" . encode($ARGV[$i]) . "'"; + $assigns = 0; + } + } + open PIPE, "| $prog" or die "cannot start process: $!"; $open = 1; } elsif ($open && $input) |