From 1118a49d4245c0d84a95dd731b1a4080c10af46e Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 28 Oct 2023 23:41:01 -0700 Subject: [PATCH] utils: Homebrew.system respect stderr This caused some JSON output to break recently which is not ideal. The change here is to check if the output should be diverted to stderr based on the options passed to system. If `:out => :err` is passed, then we should send any verbose output to stderr as well. ```console $ brew ruby -e 'Homebrew.system("ls", :out => :err)' 2>| wc -c 105 $ brew ruby -e 'Homebrew.system("ls")' | wc -c 105 ``` --- Library/Homebrew/utils.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index e2958fb775..74b1f83c24 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -43,8 +43,9 @@ module Homebrew def self.system(cmd, *args, **options) if verbose? - puts "#{cmd} #{args * " "}".gsub(RUBY_PATH, "ruby") - .gsub($LOAD_PATH.join(File::PATH_SEPARATOR).to_s, "$LOAD_PATH") + out = (options[:out] == :err) ? $stderr : $stdout + out.puts "#{cmd} #{args * " "}".gsub(RUBY_PATH, "ruby") + .gsub($LOAD_PATH.join(File::PATH_SEPARATOR).to_s, "$LOAD_PATH") end _system(cmd, *args, **options) end