diff options
Diffstat (limited to 'code/snippets/spawn_open3_eg.rb')
| -rw-r--r-- | code/snippets/spawn_open3_eg.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/code/snippets/spawn_open3_eg.rb b/code/snippets/spawn_open3_eg.rb new file mode 100644 index 0000000..0417aa0 --- /dev/null +++ b/code/snippets/spawn_open3_eg.rb @@ -0,0 +1,14 @@ +# This is available as part of the standard library. +require 'open3' + +Open3.popen3('grep', 'data') { |stdin, stdout, stderr| + stdin.puts "some\ndata" + stdin.close + puts stdout.read +} + +# Open3 will use Process.spawn when available. Options can be passed to +# Process.spawn like so: +Open3.popen3('ls', '-uhh', :err => :out) { |stdin, stdout, stderr| + puts stdout.read +} |
