[pve-devel] [PATCH installer v2 5/6] sys: command: add option to not print process output to stdout

Christoph Heiss c.heiss at proxmox.com
Tue Feb 13 16:14:02 CET 2024


If $noprint is set, the output of the command won't be printed to stdout
of the parent process.

Fully backwards-compatible again, only takes effect if the new argument
is actually specified.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
Changes since v1:
  * added parameter documentation

 Proxmox/Sys/Command.pm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Proxmox/Sys/Command.pm b/Proxmox/Sys/Command.pm
index 36e99c1..d145483 100644
--- a/Proxmox/Sys/Command.pm
+++ b/Proxmox/Sys/Command.pm
@@ -85,8 +85,9 @@ sub syscmd {
 #           to exit early and ignore the rest of the process output.
 # * $input - Stdin contents for the spawned subprocess
 # * $noout - Whether to append any process output to the return value
+# * $noprint - Whether to print any process output to the parents stdout
 sub run_command {
-    my ($cmd, $func, $input, $noout) = @_;
+    my ($cmd, $func, $input, $noout, $noprint) = @_;

     my $cmdstr;
     if (!ref($cmd)) {
@@ -178,7 +179,7 @@ sub run_command {
 	    } elsif ($h eq $error) {
 		$ostream .= $buf if !($noout || $func);
 	    }
-	    print $buf;
+	    print $buf if !$noprint;
 	    STDOUT->flush();
 	    log_info($buf);
 	}
--
2.43.0





More information about the pve-devel mailing list