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
```
This commit is contained in:
apainintheneck 2023-10-28 23:41:01 -07:00
parent 97eda64790
commit 1118a49d42

View File

@ -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