Python without a tty

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Thu Sep 29 07:50:18 EDT 2011


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> Alain Ketterlin wrote:

>>> I have a Python script which I would like to test without a tty attached
>>> to the process. I could run it as a cron job, but is there an easier way?

>> Isn't os.setsid() what you're looking for?[...]

> It doesn't appear so to me.
[...]
> [steve at sylar ~]$ python -c "import sys,os; print os.isatty(sys.stdout.fileno())"
> True
> [steve at sylar ~]$ setsid 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.

If that's what you mean by "without a tty attached", simply redirecting
standard channels should work, no?

-- Alain.



More information about the Python-list mailing list