tags:

views:

36

answers:

1

How do I tell from within a ruby script whether it has been run from the command line, i.e. like this:

> ruby myscript.rb

or from a non-interactive process, e.g. cron?

+2  A: 

$stdin.tty? will return true if connected to a terminal otherwise false.

There is a fair bit of additional information on question http://stackoverflow.com/questions/273262/best-practices-with-stdin-in-ruby

Steve Weet