stdin -> stdout

John Machin sjmachin at lexicon.net
Fri Aug 19 18:55:46 EDT 2005


limodou wrote:
> 2005/8/19, max(01)* <max2 at fisso.casa>:
> 
>>hi.
>>
>>i was wondering, what's the simplest way to echo the standard input to
>>the standard output, with no modification.
>>
>>i came up with:
>>
>>...
>>while True:
>>   try:
>>     raw_input()
>>   except EOFError:
>>     break
>>...
>>
>>but i guess there must be a simpler way.
>>
>>using bash i simply do 'cat', *sigh*!
>>
>>bye
>>
>>max
>>
>>ps: in perl you ca do this:
>>
>>...
>>while ($line = <STDIN>)
>>   {
>>     print STDOUT ("$line");
>>   }
>>...
> 
> 
> Try this.
> 
> import sys
> 
> line = sys.stdin.readline()
> while line:
>     sys.stdout.write(line)
>     line = sys.stdin.readline()
> 

Try this:

import sys
for line in sys.stdin:
    sys.stdout.write(line)






More information about the Python-list mailing list