Hi there!

How do I check if stdin is empty? This is how I write in the terminal to call my program:

>> cat file.txt | python script.py


Recommended Answers

Thanks for the information!

Jump to Post

All 2 Replies

I found the solution by myself.

use sys.stdin.isatty() to find out whether the script is executed as a part of pipeline or standalone.
The method should return True if stdin is connected to a terminal, and False otherwise (pipeline or file redirection).

Thanks for the information!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.