0

I want to store the printf output of an exe file that I call by system(foo.exe) in ruby and get the exit status. How would I do that?

GustavW
  • 21
  • 2
  • [This Question](http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby) might help – engineersmnky Aug 07 '14 at 16:26

1 Answers1

1

Open3 is the best way to do this.

require 'open3'
Open3.popen3('foo.exe') do |stdin, stdout, stderr, thr|
  status = thr.value
  output = stdout.read
  errors = stderr.read
end
Max
  • 21,123
  • 5
  • 49
  • 71