Skip to content

Instantly share code, notes, and snippets.

@reactormonk
Created November 15, 2011 18:14
Show Gist options
  • Select an option

  • Save reactormonk/1367839 to your computer and use it in GitHub Desktop.

Select an option

Save reactormonk/1367839 to your computer and use it in GitHub Desktop.
IO.popen('cat') do |io|
io.puts("foobar")
io.close_write
puts io.gets
end
@samuelkadolph

Copy link
Copy Markdown
stdin_, stdin = IO.pipe
stdout, stdout_ = IO.pipe
stderr, stderr_ = IO.pipe

pid = Process.spawn("cat", :in => stdin_, :out => stdout_, :err => stderr_)

stdin.puts "foobar"
puts stdout.gets

Process.kill(:TERM, pid)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment