3

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?

Simon
  • 25,468
  • 44
  • 152
  • 266

1 Answers1

5

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

There is a fair bit of additional information on question Best practices with STDIN in Ruby?

Community
  • 1
  • 1
Steve Weet
  • 28,126
  • 11
  • 70
  • 86