Readling all input from stdin
bokr at oz.net
Mon Jul 28 22:00:39 CEST 2003
On Mon, 28 Jul 2003 13:25:33 +0200, Svenne Krap <usenet2003 at krap.dk> wrote:
>I am writing a small script, that is called from an external program
>(the qmail mailserver), I need to capture all input from stdin before
>continueing the script ..
>I looked for sys.stdin.readlines() but that is not present. I found
>sys.stdin.readline(), but how do I loop through it (or rather how do I
>know, when I am finished with looping ?)
>Thanks in advance
====< stdinlines.py >=======================================================
data = sys.stdin.read()
for line in data.splitlines(True): # keeps \n ends. (False) or () would not
print repr(line) # to see all chars represented
(I have a cat on my NT that copies stdin to stdout in text mode until it sees ^Z as EOF):
[13:00] C:\pywk\clp>cat | python stdinlines.py
three spaces to left
three spaces to right
three spaces both sides
next line is empty
last line with no EOL^Z
' three spaces to left\n'
'three spaces to right \n'
' three spaces both sides \n'
'next line is empty\n'
'last line with no EOL'
More information about the Python-list