prog1 | prog2 . How not to make prog2 block if not piped?
Maric Michaud
maric at aristote.info
Wed Jun 14 11:40:36 EDT 2006
Le Mercredi 14 Juin 2006 17:13, riquito at gmail.com a écrit :
> # script1.py #
> print 'something'
>
> #script2.py
> x=sys.stdin.read()
read() will read a file object to the end, i guess you want to use readline()
instead or the builtin raw_input.
> print 'passed'
>
> if I run
> script1.py | script2.py
> all goes well.
This is because when script1.py ends, it will send an 'EOF' char to
script2.py, wich terminate the read method.
>
> But if I run just
> script2.py
> the program blocks waiting forever for input.
here, newlines ('\n'), doesn't terminate the read call, you can stop the read
by typing ctrl+d at the beginnning of a new line in a normal unix terminal.
--
_____________
Maric Michaud
_____________
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
More information about the Python-list
mailing list