15 - redirecting standard input or output.rb

来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 20 行

RB
20
字号
#!/usr/bin/env ruby# redirect_stdout.rbrequire 'stringio'new_stdout = StringIO.new$stdout = new_stdoutputs 'Hello, hello.'puts "I'm writing to standard output."$stderr.puts "#{new_stdout.size} bytes written to standard ouput so far."$stderr.puts "You haven't seen it on the screen yet, but you soon will:"$stderr.puts new_stdout.string#---$ ruby redirect_stdout.rb46 bytes written to standard output so far.You haven't seen it on the screen yet, but you soon will:Hello, hello.I'm writing to standard output.#---

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?