Search code examples
rubystringpopen

Store value in stdout from popen3 in Ruby


How can I store the string value in stdout from the following Ruby code?

stdin, stdout, stderr = Open3.popen3('grep something test.txt')

I can display the value like this: stdout.gets. However trying to store the value like this: s = stdout.gets just sets s to nil. Trying to store the value like this: s = stdout stores something like "#<IO:0x1003abe10>" in s.


Solution

  • output = stdout.read seems to work.