From: Eric Hodel Date: 2005-10-27T16:44:17+09:00 Subject: Re: Detection of redirection, possible? On Oct 26, 2005, at 11:44 PM, Shannon Fang wrote: > Hi All, > > 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. I think you want IO#tty?: $ ruby -e 'p $stdin.tty?' true $ ruby -e 'p $stdin.tty?' < /dev/zero false -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04