Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to catch error with system()

Reply
Thread Tools

how to catch error with system()

 
 
eight02645999@yahoo.com
Guest
Posts: n/a
 
      12-12-2005
hi

i have a piece of python code extract that calls an external java
program
cmd = """java someclass someargs"""
try:
ret = os.WEXITSTATUS(os.system(cmd))
except:
print blah
else:
dosomething(ret)

the thing is, the java class "someclass" produces it's own errors when
something goes wrong.
something like
java.io.FileNotFoundException: somefile (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
at java.io.FileInputStream.<init>(FileInputStream.jav a:66)
......

how can i supress this error from showing when i execute
../pythonscript.py and at the same time logging it to an errlog file??

thanks

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      12-12-2005
wrote:

> hi
>
> i have a piece of python code extract that calls an external java
> program
> cmd = """java someclass someargs"""
> try:
> ret = os.WEXITSTATUS(os.system(cmd))
> except:
> print blah
> else:
> dosomething(ret)
>
> the thing is, the java class "someclass" produces it's own errors when
> something goes wrong.
> something like
> java.io.FileNotFoundException: somefile (No such file or directory)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
> at java.io.FileInputStream.<init>(FileInputStream.jav a:66)
> ......
>
> how can i supress this error from showing when i execute
> ./pythonscript.py and at the same time logging it to an errlog file??


You probably want to catche the subprocesses stdout/stderr streams. To do
so, use the subprocess module (if you are on python2.4), or the
popen2-module. See the docs for how to use them.

--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
catch doesn't catch a thrown exception Marteno Rodia Java 5 08-05-2009 03:30 AM
How to catch error 401 access denied and redirect to custom error page ? rote ASP .Net 4 08-04-2008 07:27 PM
catch(...) doesn't catch everything Adam C++ 9 02-02-2006 05:02 PM
why catch (...) can not catch such exception John Black C++ 8 08-20-2004 02:34 PM



Advertisments