Interview Prep/Python for DevOps/OS, filesystem, subprocess & CLIs

How do you check whether stdout is a terminal, and why would you?

IntermediateConceptOS, filesystem, subprocess & CLIs
Answer

sys.stdout.isatty() is True for an interactive terminal and False when piped or redirected (CI logs, | jq, > file). Use it to disable colors and progress bars, emit JSON by default in pipelines, and refuse interactive prompts. sys.stdin.isatty() tells you if you can prompt the user at all.

All Python for DevOps questions Roadmap: Python for automation

More on OS, filesystem, subprocess & CLIs