From 9425c5a2e787fcbe28d0a0f5d2f916ca81d2dc48 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Thu, 10 Apr 2025 19:54:07 +0200 Subject: [PATCH] Send show_jid output to stderr When using --out=json, all data sent to stdout should be valid JSON to allow for piping into processing tools such as `jq`. Make this the case with "show_jid" being enabled as well, by printing the JID line to stderr instead of stdout. Signed-off-by: Georg Pfuetzenreuter --- changelog/25154.fixed.md | 1 + salt/client/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelog/25154.fixed.md diff --git a/changelog/25154.fixed.md b/changelog/25154.fixed.md new file mode 100644 index 000000000000..d8c449c5c2f7 --- /dev/null +++ b/changelog/25154.fixed.md @@ -0,0 +1 @@ +Send show_jid output to stderr diff --git a/salt/client/__init__.py b/salt/client/__init__.py index 5f5d0b24c0d5..1d824cfa23f8 100644 --- a/salt/client/__init__.py +++ b/salt/client/__init__.py @@ -1058,7 +1058,7 @@ def get_cli_returns( print(msg) print("-" * len(msg) + "\n") elif show_jid: - print(f"jid: {jid}") + print(f"jid: {jid}", file=sys.stderr) if timeout is None: timeout = self.opts["timeout"] fret = {} @@ -1550,7 +1550,7 @@ def get_cli_static_event_returns( print(msg) print("-" * len(msg) + "\n") elif show_jid: - print(f"jid: {jid}") + print(f"jid: {jid}", file=sys.stderr) if timeout is None: timeout = self.opts["timeout"] @@ -1644,7 +1644,7 @@ def get_cli_event_returns( print(msg) print("-" * len(msg) + "\n") elif show_jid: - print(f"jid: {jid}") + print(f"jid: {jid}", file=sys.stderr) # lazy load the connected minions connected_minions = None