I put a python program in cron and it starts behaving different.
#!/usr/bin/env python3 import sys import os import stat from os import isatty #https://python-forum.io/thread-10606.html print("stdin") print("isatty", isatty(sys.stdin.fileno()) ) mode = os.fstat(0).st_mode print("ISFIFO", stat.S_ISFIFO(mode) ) print("ISREG", stat.S_ISREG(mode) ) print("ISLNK", stat.S_ISLNK(mode) ) print("ISDIR", stat.S_ISDIR(mode) ) print("ISCHR", stat.S_ISCHR(mode) ) print("ISBLK", stat.S_ISBLK(mode) ) print("ISSOCK", stat.S_ISSOCK(mode) ) print("done")
Apparently, using istty isn’t reliable indicator that you are getting redirected data. I guess I can accept that, since cron intuitively doesn’t have a terminal. So what is the stdin of a Linux Daemon?
This doesn’t answer it:
https://unix.stackexchange.com/questions/278105/what-are-the-default-stdin-and-stdout-of-a-child-process
In fact, I can’t Google the answer. But I tried checking all the possible stat tests. And when I ran it in cron…
stdin isatty False ISFIFO True ISREG False ISLNK False ISDIR False ISCHR False ISBLK False ISSOCK False done
I can accept a lot of things. But why is a cronjob, which I assume inherits stdin from cron, have a stdin that python considers a fifo pipe? This is the very logic, I would’ve used to check if stdin was redirected from output of another process.
This is a fantastic failure, b/c it is very strange.