Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fool python's os.isatty from a bash script

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.

like image 370
Dogsbody Avatar asked Apr 16 '13 16:04

Dogsbody


1 Answers

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
like image 102
shx2 Avatar answered Sep 19 '22 12:09

shx2