]> git.proxmox.com Git - pve-common.git/commitdiff
run_command: add 'quiet' parameter for omitting STD* prints
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 19 Dec 2017 10:50:16 +0000 (11:50 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 19 Dec 2017 12:09:07 +0000 (13:09 +0100)
Without this patch we printed to STDOUT and STDERR, respectively, if
no $outfunc or $errfunc was passed.

Sometimes it's useful if one, or even both, of those prints can
be suppressed, currently this can only be done by either using an array
of arrays or a whole string for the command and redirecting STDOUT
and STDERR.

Add a 'quiet' option which allows to do this in an easier way.
It allows to silent STDERR or STDOUT or both.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Tools.pm

index f43424bb7307095debd575840b6495bb828eaf48..f91d35a1df52aa3a49acd8ebedf50147d08f8ceb 100644 (file)
@@ -369,6 +369,7 @@ sub run_command {
     my $afterfork;
     my $noerr;
     my $keeplocale;
     my $afterfork;
     my $noerr;
     my $keeplocale;
+    my $quiet;
 
     eval {
 
 
     eval {
 
@@ -395,6 +396,8 @@ sub run_command {
                $noerr = $param{$p};
            } elsif ($p eq 'keeplocale') {
                $keeplocale = $param{$p};
                $noerr = $param{$p};
            } elsif ($p eq 'keeplocale') {
                $keeplocale = $param{$p};
+           } elsif ($p eq 'quiet') {
+               $quiet = $param{$p};
            } else {
                die "got unknown parameter '$p' for run_command\n";
            }
            } else {
                die "got unknown parameter '$p' for run_command\n";
            }
@@ -497,7 +500,7 @@ sub run_command {
                            waitpid ($pid, 0);
                            die $err;
                        }
                            waitpid ($pid, 0);
                            die $err;
                        }
-                   } else {
+                   } elsif (!$quiet) {
                        print $buf;
                        *STDOUT->flush();
                    }
                        print $buf;
                        *STDOUT->flush();
                    }
@@ -517,7 +520,7 @@ sub run_command {
                            waitpid ($pid, 0);
                            die $err;
                        }
                            waitpid ($pid, 0);
                            die $err;
                        }
-                   } else {
+                   } elsif (!$quiet) {
                        print STDERR $buf;
                        *STDERR->flush();
                    }
                        print STDERR $buf;
                        *STDERR->flush();
                    }