[pve-devel] applied: [RFC common v2] run_command: add 'quiet' parameter for omitting STD* prints
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Dec 19 13:13:10 CET 2017
applied
On Tue, Dec 19, 2017 at 11:50:16AM +0100, Thomas Lamprecht wrote:
> 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 at proxmox.com>
> ---
>
> changes v1 -> v2:
> * s/quite/quiet/ sorry for the noice and thanks emmanuel for catching...
Not quite, but I FTFY ;-)
>
> src/PVE/Tools.pm | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
> index 7efd0dd..b34c8b7 100644
> --- a/src/PVE/Tools.pm
> +++ b/src/PVE/Tools.pm
> @@ -369,6 +369,7 @@ sub run_command {
> my $afterfork;
> my $noerr;
> my $keeplocale;
> + my $quite;
>
> eval {
>
> @@ -395,6 +396,8 @@ sub run_command {
> $noerr = $param{$p};
> } elsif ($p eq 'keeplocale') {
> $keeplocale = $param{$p};
> + } elsif ($p eq 'quite') {
> + $quite = $param{$p};
> } else {
> die "got unknown parameter '$p' for run_command\n";
> }
> @@ -497,7 +500,7 @@ sub run_command {
> waitpid ($pid, 0);
> die $err;
> }
> - } else {
> + } elsif (!$quite) {
> print $buf;
> *STDOUT->flush();
> }
> @@ -517,7 +520,7 @@ sub run_command {
> waitpid ($pid, 0);
> die $err;
> }
> - } else {
> + } elsif (!$quite) {
> print STDERR $buf;
> *STDERR->flush();
> }
> --
> 2.11.0
More information about the pve-devel
mailing list