get the return code when piping something to a python script?

Paul Watson pwatson at redlinepy.com
Tue Aug 16 14:56:29 EDT 2005


mhenry1384 wrote:
> On WinXP, I am doing this
> 
> nant.exe | python MyFilter.py
> 
> This command always returns 0 (success) because MyFilter.py always
> succeeds.
> 
> MyFilter.py looks like this
> 
> while 1:
>     line = sys.stdin.readline()
>     if not line:
>         break
>     ...
>     sys.stdout.write(line)
>     sys.stdout.flush()
> 
> How do I set the return code from MyFilter.py based on the return of
> nant.exe?  Is this possible?  I have googled around for an hour wihtout
> success.  I understand that I could have MyFilter.py call "nant.exe",
> but for various reasons, that's not idea for my situation.

As you have heard, it may not be possible to get the exit code from a 
command line pipe.

Of course, even if you could, this code does not yet set an exit code.

sys.exit(exitcode)



More information about the Python-list mailing list