473,545 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to catch error with system()

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.FileNot FoundException: somefile (No such file or directory)
at java.io.FileInp utStream.open(N ative Method)
at java.io.FileInp utStream.<init> (FileInputStrea m.java:106)
at java.io.FileInp utStream.<init> (FileInputStrea m.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

Dec 12 '05 #1
1 2391
ei***********@y ahoo.com 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.FileNot FoundException: somefile (No such file or directory)
at java.io.FileInp utStream.open(N ative Method)
at java.io.FileInp utStream.<init> (FileInputStrea m.java:106)
at java.io.FileInp utStream.<init> (FileInputStrea m.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.

--
Regards,

Diez B. Roggisch
Dec 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5973
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
23
3042
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally block. But, I prefer to dim them "on the fly" only if needed (save as much resources as possible). A little further... I may wish to create a sqlcommand...
3
1837
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call a mehtod called ExceptionGenerator that will generate a run-time exception. The exception is caught in GenericGridEvent, but it isn't caught in...
2
1922
by: Ralph Krausse | last post by:
I created a try/catch/finally but when an expection is thrown, the catch does not handle it... (I know this code is wrong, I want to force the error for this example) try { DataSet ds = new DataSet(); string strID = ds.Tables.Rows.ToString(); }
8
1681
by: CarpetMnuncher! | last post by:
================================================================= How do I use Try Catch error handling when a timer is involved? If I preform the preciduer below and I get an error I revive 50,000,000,000,000,000, messageboxes.. example 1; Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
7
1367
by: Tiraman | last post by:
Hi , I am using allot the try catch in my code and the question is if it is good ? it will decrease my performance ? one more question
2
4426
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist then skip this file and move onto the next file (line). If file is there then move to a sirectory. Here is the code I have (Feel free to make...
5
1751
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with multiple Catch statements, or do I have to figure out how to embed Try Catch statements into my code. The scenario is this (and I'll paste the...
2
1907
by: CodeSlayer | last post by:
Hi all, This one really has me and the other .Net developers at my work stumped. I have an application that is doing the following: 1 - attempt to validate that user can create a windows task via COM interops 2 - an exception is thrown because user doesn't exist 3 - Exception is caught by calling code shown below:
4
4516
by: andyehi | last post by:
Dear All, I am new to C# and I am developing an application which will 24hours run on the remote PC..To transfer records from mysql to access db.I have succesfully created the application and have to handle the ODBC error and standard error.Basically it has to skip the error and move to next record.I really dont know how to use try catch.I...
0
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7411
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7749
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5965
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1871
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.