catching error output

Wayne Pierce wayne at mishre.com
Tue Feb 12 15:18:14 EST 2002


Joseph,

   Have you tried one of the other versions[1] of os.popen?  The other 
versions don't return a status code, but they do let you read the stdin, 
stderr and stdout.

   You might try one of the other versions, then read() from stderr, 
inside a try block, to see if there was an error or not.  If there was 
no error, read from the stdout.

[1] http://www.python.org/doc/current/lib/os-newstreams.html

Joseph Holland King wrote:
> in a small script i am using the popen command to run a command 
> and then parse the output:
> fs = os.popen('foo some_data')
> fs.readline()
> ...
> however when foo fails i need to catch that error and be able to parse
> it. is there anyway to do this? fs = .. does not catch it just the 
> normal output. thanks.
> 
> --
> Holland King        
> gte743n at cad.gatech.edu
> 


-- 
Wayne Pierce
web: http://www.mishre.com
email: wayne at mishre.com

"What you need to know."





More information about the Python-list mailing list