How to recognize whether a script is running on a tty?

前端 未结 1 748
悲&欢浪女
悲&欢浪女 2020-11-30 03:01

I would like my script to act differently in an interactive shell session and when running with redirected stdout (for example when piped to some other command).

How

相关标签:
1条回答
  • 2020-11-30 03:21
    import os, sys
    os.isatty(sys.stdout.fileno())
    

    or

    sys.stdout.isatty()
    
    0 讨论(0)
提交回复
热议问题