Rubyで自分自身のSTDERRを読む
What's this?
Reading own STDERR in Ruby
Source code
read,write = IO.pipe # make pipe STDERR.reopen(write) # STDERR ---> write ---> read # example STDERR.puts "hello" p read.gets
おわりに
パイプの仕組みを理解していないので、試行錯誤しながら作りました。
もっといいやり方があったら教えて下さい。
STDOUTとSTDERRを交換する (Swapping stdout and stderr)
( http://docstore.mik.ua/orelly/perl/cookbook/ch16_08.htm )
ls 3>&1 1>&2 2>&3 3>&-