Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: km Newsgroups: comp.lang.python Subject: is input from a pipe? Date: Wed, 15 Jan 2025 18:31:34 -0000 (UTC) Organization: A noiseless patient Spider Lines: 20 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 15 Jan 2025 19:31:34 +0100 (CET) Injection-Info: dont-email.me; posting-host="5683a4545d47de94f93ca8a2792b1b68"; logging-data="3217721"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wh5JHke2be9fgDGgomXMT" User-Agent: Pan/0.160 (Toresk; ) Cancel-Lock: sha1:0mvXK02jdyPlu9VNhNxWQUBhqFk= Xref: csiph.com comp.lang.python:197191 Not a question, but a quick note about a problem that sometimes pops up in forums, that is how to detect on Linux if standard input (or any I/O stream) is via pipe. My suggestion is to check if the stream is a FIFO, if True it is a pipe, otherwise not a pipe The solution that sometimes is proposed, that is if not sys.stdin.isatty() simply checks if the input is not from a terminal, but it may be from a file, not only from a pipe. import os import sys import stat def check_if_stream_is_pipe(ifile): return stat.S_ISFIFO(os.fstat(ifile.fileno()).st_mode) print(check_if_stream_is_pipe(sys.stdin))