Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open.popen3 does not set $? #5520

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions lib/cask/system_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ def self.run(executable, options={})
command = _process_options(executable, options)
odebug "Executing: #{command.utf8_inspect}"
output = ''
Open3.popen3(*command) do |stdin, stdout, stderr|
if options[:input]
options[:input].each { |line| stdin.puts line }
end
stdin.close_write
while line = stdout.gets
output << line
ohai line.chomp if options[:print]
end
while line = stderr.gets
next if options[:stderr] == :silence
output << line
ohai line.chomp if options[:print]
end
exit_status = nil

ext_stdin, ext_stdout, ext_stderr, wait_thr = Open3.popen3(*command)
if options[:input]
options[:input].each { |line| ext_stdin.puts line }
end
_assert_success($?, command, output) if options[:must_succeed]
ext_stdin.close_write
while line = ext_stdout.gets
output << line
ohai line.chomp if options[:print]
end
while line = ext_stderr.gets
next if options[:stderr] == :silence
output << line
ohai line.chomp if options[:print]
end
ext_stdout.close_read
ext_stderr.close_read

# Ruby 1.8 sets $?. Ruby 1.9+ has wait_thr, and does not set $?.
exit_status = wait_thr.nil? ? $? : wait_thr.value

_assert_success(exit_status, command, output) if options[:must_succeed]
if options[:plist]
_parse_plist(command, output)
else
Expand Down Expand Up @@ -49,7 +56,7 @@ def self._process_options(executable, options)
end

def self._assert_success(status, command, output)
unless status.success?
unless status and status.success?
raise CaskCommandFailedError.new(command.utf8_inspect, output, status)
end
end
Expand Down