From f912566320b1a877f64540b833f70e4fe7a85874 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 25 Oct 2011 12:18:41 +0200 Subject: [PATCH] add split_args helper function --- data/PVE/Tools.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 78d7b9f..5cd8460 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -709,4 +709,30 @@ sub shellquote { return $str; } +# a clumsy way to split an shell argument string into an array, +# we simply pass it to the cli (exec call) +# fixme: use Text::ParseWords::shellwords() ? +sub split_args { + my ($str) = @_; + + my $args = []; + + return $args if !$str; + + my $cmd = 'perl -e \'foreach my $a (@ARGV) { print "$a\n"; } \' -- ' . $str; + + eval { + run_command($cmd, outfunc => sub { + my $data = shift; + push @$args, $data; + }); + }; + + my $err = $@; + + die "unable to parse args: $str\n" if $err; + + return $args; +} + 1; -- 2.39.2