Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Caution: Keep out of reach of children.


comp / comp.lang.python / is input from a pipe?

SubjectAuthor
o is input from a pipe?km

1
Subject: is input from a pipe?
From: km
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Wed, 15 Jan 2025 18:31 UTC
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: kammamuri@libero.it (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: <vm8uu5$3269p$1@dont-email.me>
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=
View all headers

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))

1

rocksolid light 0.9.8
clearnet tor