new helper cmd2string

This commit is contained in:
Dietmar Maurer 2011-12-01 07:37:22 +01:00
parent a0f855e64c
commit 65e1d3fc9c

View File

@ -170,7 +170,7 @@ sub run_command {
$cmd = [ $cmd ] if !ref($cmd); $cmd = [ $cmd ] if !ref($cmd);
my $cmdstr = join (' ', @$cmd); my $cmdstr = cmd2string($cmd);
my $errmsg; my $errmsg;
my $laststderr; my $laststderr;
@ -695,6 +695,19 @@ sub shellquote {
return String::ShellQuote::shell_quote($str); 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, # split an shell argument string into an array,
sub split_args { sub split_args {
my ($str) = @_; my ($str) = @_;