且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何确定是否从crontab执行python脚本?

更新时间:2023-11-28 19:17:16

不是您要求的内容,但也许你想要的是 os.isatty(sys.stdout.fileno()),它告诉 stdout (大致而言)连接到终端。如果将输出传递到文件或另一个进程,或者从cron运行进程,则它将为false。

Not quite what you asked, but maybe what you want is os.isatty(sys.stdout.fileno()), which tells if stdout is connected to (roughly speaking) a terminal. It will be false if you pipe the output to a file or another process, or if the process is run from cron.