If stdin is empty?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2007
Posts: 23
Reputation: flaerpen is an unknown quantity at this point 
Solved Threads: 1
flaerpen flaerpen is offline Offline
Newbie Poster

If stdin is empty?

 
0
  #1
Jul 17th, 2007
Hi there!

How do I check if stdin is empty? This is how I write in the terminal to call my program:
  1. >> cat file.txt | python script.py

/flaerpen
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 23
Reputation: flaerpen is an unknown quantity at this point 
Solved Threads: 1
flaerpen flaerpen is offline Offline
Newbie Poster

Re: If stdin is empty?

 
0
  #2
Jul 19th, 2007
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).
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,042
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 933
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: If stdin is empty?

 
0
  #3
Jul 19th, 2007
Thanks for the information!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC