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?

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.