prog1 | prog2 . How not to make prog2 block if not piped?
Steve Holden
steve at holdenweb.com
Wed Jun 14 16:31:39 EDT 2006
imcs ee wrote:
> yeah, forget my post ,it;s useless.
> sorry for my thoughtless
> On 14 Jun 2006 10:40:15 -0700, riquito at gmail.com <riquito at gmail.com> wrote:
>
>>imcs ee ha scritto:
>>
>>
>>>do u really need read something even when you run the scripts2.py directly?
>>>why not just change script2.py to
>>> #script2.py
>>>if __name__ == "__main__":
>>> x=sys.stdin.read()
>>> print 'passed'
>>>else:
>>> print 'passed from else branch'
>>>
>>>is it what you want? or anything i misunderstand.
>>
>>it won't do. clever btw.
>>Script2 is not a module, it's a program that _could_ receive input via
>>pipe.
>>
It really doesn't matter *how* it receives input, whether from a pipe,
or a terminal or a redirected file.
When you run it "standalone" you should give it some input - type some
text then enter ^D (on Unix-like systems) or ^Z (on Windows). How else
do you expect read() to return anything? It *has* to read to the end fo
the file before it returns a value.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list