Python without a tty

Hans Mulder hansmu at
Thu Sep 29 13:50:29 CEST 2011

On 29/09/11 12:52:22, Steven D'Aprano wrote:

> [steve at sylar ~]$ python -c "import sys,os; print os.isatty(sys.stdout.fileno())"
> True
> If I run the same Python command (without the setsid) as a cron job, I
> get False emailed to me. That's the effect I'm looking for.

In that case, all you need to do is redirect stdout:

$ python -c "import sys, os
 > print os.isatty(sys.stdout.fileno())" >/tmp/xxx
$ cat /tmp/xxx

You'll probably want to redirect to /dev/null and
maybe you want to redirect stdin and stderr as well.

-- HansM

More information about the Python-list mailing list