how to catch error with system()

E

eight02645999

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.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java: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
 
D

Diez B. Roggisch

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.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java: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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top