sys.stdout.isatty() code example
Example: python detect tty
if sys.stdout.isatty():
# You're running in a real terminal
else:
# You're being piped, redirected, cron
if sys.stdout.isatty():
# You're running in a real terminal
else:
# You're being piped, redirected, cron