From: Dietmar Maurer Date: Thu, 13 Oct 2011 11:55:49 +0000 (+0200) Subject: allow input/output redirection in run_command X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=1c50a24addb8c7e589c98c586db86aefd98bea6e allow input/output redirection in run_command Those changes are needed by new vzdump code. --- diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 985b31e..9ced12a 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -177,11 +177,8 @@ sub run_command { my $pid; eval { - my $reader = IO::File->new(); - my $writer = IO::File->new(); - my $error = IO::File->new(); - my $input; + my $output; my $outfunc; my $errfunc; @@ -198,6 +195,8 @@ sub run_command { }; } elsif ($p eq 'input') { $input = $param{$p}; + } elsif ($p eq 'output') { + $output = $param{$p}; } elsif ($p eq 'outfunc') { $outfunc = $param{$p}; } elsif ($p eq 'errfunc') { @@ -207,6 +206,10 @@ sub run_command { } } + my $reader = $output && $output =~ m/^>&/ ? $output : IO::File->new(); + my $writer = $input && $input =~ m/^<&/ ? $input : IO::File->new(); + my $error = IO::File->new(); + # try to avoid locale related issues/warnings my $lang = $param{lang} || 'C'; @@ -312,12 +315,14 @@ sub run_command { } elsif (my $sig = ($? & 127)) { die "got signal $sig\n"; } elsif (my $ec = ($? >> 8)) { - if ($errmsg && $laststderr) { - my $lerr = $laststderr; - $laststderr = undef; - die "$lerr\n"; + if (!($ec == 24 && ($cmdstr =~ m|^(\S+/)?rsync\s|))) { + if ($errmsg && $laststderr) { + my $lerr = $laststderr; + $laststderr = undef; + die "$lerr\n"; + } + die "exit code $ec\n"; } - die "exit code $ec\n"; } alarm(0); @@ -346,6 +351,8 @@ sub run_command { die "command '$cmdstr' failed: $err"; } } + + return undef; } sub split_list {