7

I am writing a bash script that will be called from cron.

The bash script runs a python command that is sensing when it's in a terminal by using pythons os.isatty function and outputs different things depending on if it's run manually or via a cron. This is making debugging very hard and I would like to make it so that it always assumes it ISN'T in a TTY.

I would like to be able to add something to the bash script to fool the python script that it is not being run in a terminal and so always output the same thing.

To confirm, I have control of the bash script but don't want to edit the python as this is a packaged app.

Any ideas?

I hope that made sense.

Thank you very much in advance.

shx2
  • 61,779
  • 13
  • 130
  • 153
Dogsbody
  • 293
  • 1
  • 11

1 Answers1

7

You can redirect the output to cat (assuming the script tests sys.stdout's file descriptor's atty-ness).

python myscript.py | cat

a.py

import sys
print sys.stdout.isatty()

to test:

> python a.py
True
> python a.py | cat
False
shx2
  • 61,779
  • 13
  • 130
  • 153