4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python スクリプト実行時に標準出力がパイプされているかどうか判断する

Last updated at Posted at 2017-04-11

実行時に標準出力がパイプされているかどうか判断するにはisattyを使う - Qiita

これを Python でもやろうと思って調べたのでメモ。

isatty.py
import sys

print(sys.stdout.isatty())

実行するとこうなる

$ python isatty.py
True
$ python isatty.py | cat
False

補足

これでもいいっぽい

isatty.py
import os, sys

print(os.isatty(sys.stdout.fileno()))
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?