public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] fix #4333: redirect API handler output to STDERR
Date: Wed,  8 Mar 2023 12:47:09 +0100	[thread overview]
Message-ID: <20230308114709.3391029-1-f.gruenbichler@proxmox.com> (raw)

otherwise, print/warn statements by the API endpoint are included in the
output, which breaks JSON parsing in case of output-format == json*.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---

Notes:
    technically a change that might require adapting some scripted calls, although
    we don't give any guarantees about pvesh output (or task log contents/stdout
    output of endpoints) I think ;)
    
    Suggested-by: reitermarkus (Proxmox Community Forum user)

 PVE/CLI/pvesh.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/PVE/CLI/pvesh.pm b/PVE/CLI/pvesh.pm
index 9acf292a..31dce26d 100755
--- a/PVE/CLI/pvesh.pm
+++ b/PVE/CLI/pvesh.pm
@@ -309,7 +309,13 @@ sub call_api_method {
 	    $param->{$p} = $uri_param->{$p};
 	}
 
-	$data = $handler->handle($info, $param);
+	do {
+	    # redirect stray output to STDERR
+	    # only the returned $data should go to STDOUT
+	    local *STDOUT;
+	    open(STDOUT, '>&', STDERR);
+	    $data = $handler->handle($info, $param);
+	};
     }
 
     return if $opt_nooutput || $stdopts->{quiet};
-- 
2.30.2





             reply	other threads:[~2023-03-08 11:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 11:47 Fabian Grünbichler [this message]
2023-03-11 17:10 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308114709.3391029-1-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal