From: Dietmar Maurer Date: Thu, 1 Dec 2011 06:37:22 +0000 (+0100) Subject: new helper cmd2string X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=65e1d3fc9c3093e156dd2581704e31b5415c12d5;ds=sidebyside new helper cmd2string --- diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index b42a5bb..1a8d33c 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -170,7 +170,7 @@ sub run_command { $cmd = [ $cmd ] if !ref($cmd); - my $cmdstr = join (' ', @$cmd); + my $cmdstr = cmd2string($cmd); my $errmsg; my $laststderr; @@ -695,6 +695,19 @@ sub shellquote { return String::ShellQuote::shell_quote($str); } +sub cmd2string { + my ($cmd) = @_; + + die "no arguments" if !$cmd; + + return $cmd if !ref($cmd); + + my @qa = (); + foreach my $arg (@$cmd) { push @qa, shellquote($arg); } + + return join (' ', @qa); +} + # split an shell argument string into an array, sub split_args { my ($str) = @_;