How can I detect a ruby program's stdio has been redirected? I would like to
do this:
puts "show message to user"
$stdin.gets unless $stdin.redirected?
This way, if the program runs normally, it show message and wait for user
interaction, if it is redirected to a file, then just puts to that file
without wating for user intervention.
Thanks!
Shannon
I think you want IO#tty?:
$ ruby -e 'p $stdin.tty?'
true
$ ruby -e 'p $stdin.tty?' < /dev/zero
false
--
Eric Hodel - drb...@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
At Thu, 27 Oct 2005 15:44:54 +0900,
Shannon Fang wrote in [ruby-talk:162881]:
> puts "show message to user"
$stdin.gets if $stdin.tty?
--
Nobu Nakada