These three ways to run sub-processes should have enough similarities to render them exchangeable in many contexts. However, I do not seem to understand how I could use Open3::capture2 (for example) as a replacement for IO::popen or TTY::Command.run without running into errors. For the time I give up on Open3. The documentation is incomplete or written for somebody else.
Code:
require 'tty-command'
require 'open3'
cmd = TTY::Command.new
out,err = cmd.run("cat", "/tmp/test", printer: :null)
out.to_s
=> "line 1\nline 2\n"
out, status = Open3.capture2("cat", :stdin_data => "/tmp/test")
out.to_s
=> "/tmp/test"
out = IO.popen("cat /tmp/test")
out.read
=> "line 1\nline 2\n"
Providing blocks to the Open3-methods should allow many cool things, but I cannot figure it out. Too many conditions might have to be met. Listing them does not suffice, it must also run, sometimes.
I have not used subprocess and stick to TTY::Command for a while.