Redirecting Standard Input or Output
#!/usr/bin/env ruby # redirect_stdout.rb require 'stringio' new_stdout = StringIO.new $stdout = new_stdout puts 'Hello, hello.' puts "I'm writing to standard output." $stderr.puts "#{new_stdout.size} bytes written to standard ouput so far." $stderr.puts "AAA" $stderr.puts new_stdout.string $ ruby redirect_stdout.rb
1. | Performing Random Access on Read-Once Input Streams | ||
2. | Pretending a String is a File | ||
3. | Write to a string | ||
4. | YAML.dump | ||
5. | Find the fifth byte | ||
6. | push data to string |