How to trap a java exception where java is invoked from a .bat file

Hi,
Jgurus,
i have problem here, i am invoking a batch file from my java class using the command Runtime.getRuntime().exec(batch1.bat) now this file is setting some classpath and invoking batch2.bat with some parameters and this batch2.bat is invoking java command which is throwing a exception now i want trap this execption.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
:::::code for batch1.bat:::::
set classpath=d:\com\tech\sun\tcc.jar;d:\com\tech\sun\parameter.jar
set TMMHOME=d:\TMM
cd %TMMHome%\bin
testcom.bat -i D:/test1.xml -o D:/testresult.xml
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
:::::code for testcom.bat:::::
%_JAVACMD% -classpath %LOCALCLASSPATH% com.tech.sun.parameter
now when java is invoked it throws an error :
Exception in thread "main" com.tech.test.runner.RunnerException: com
.snstech.testcompanion.runner.RunnerException: com.snstech.testcompanion.runner.
RunnerException: The specified constructor for aclass does not exist
pls. help me in this issue .....
thanks in advance
Abhijit
[email protected]

>
You can read the output stream of that other process.
Process p = Runtime.getRuntime().exec(...);
InputStream theOutput = p.getInputStream();
// or you may want the p.getErrorStream()
// now read and parse theOutputAre you sure that will work from an exe in a batch file? It was my understanding that a batch file runs in a shell (a process.) When an executable runs in the batch file a seperate process is created. Thus I would expect that it would have its own stdin/out/err in that case.
However, in newer versions of windows the following will redirect the output to files (there is NO space between the '2' and the '>')
java.exe MyClass >out.txt 2>err.txt
This will work if the above does not (and if your version of windows supports it.)

Similar Messages

  • When Uploading a video, I am given a "Online services encountered an error. The Service will now be terminated or paused if possible." How do I fix this? Where did it come from?

    When Uploading a video, I am given a "Online services encountered an error. The Service will now be terminated or paused if possible." How do I fix this? Where did it come from?

    Provide the name of the program you are using so a Moderator may move this message to the correct program forum
    This Cloud forum is not about help with program problems... a program would be Photoshop or Lighroom or Muse or ???

  • How to access custom JAVA webdynpro application from an iPad?

    Hi,
    We are trying to access custom JAVA webdynpro application from an iPad, but nothing is opening up from the iPad browser.
    What can be the possible reasons for this? Any kind of SICF enablement or opening up of ports in the network?
    Any inputs are welcome!!
    TIA,
    Regards
    Deepthi

    Hi,
    it is possible to show Java Web Dynpro applications on a mobile device in general, but the controls and the ui should be optimized for the mobile device.
    Safari devices are not officially supported so far for Mobile Web Dynpro.
    Supported are Windows Mobile devices and Blackberry devices. I also got some good results with Symbian devices.
    You can find more inforamtion on Mobile Always Connected at:
    ht[http://help.sap.com/saphelp_nwce711core/helpdata/en/7d/28fa3e7cb1d861e10000000a114084/content.htm|http://help.sap.com/saphelp_nwce711core/helpdata/en/7d/28fa3e7cb1d861e10000000a114084/content.htm]
    Best Regards,
    Stefan

  • Execute java code taken from a properties file

    I have a requirement to store some java code in the Properties file & use the code inside the program later. Is there a way I can execute this code after I get it from the .properties file which is retrieved using the ResourceBundle?
    Example:
    File: system.properties
    Item_list=blocksBean.menu(QueryValue,request.getContextPath())
    Inside my Java program I'm using this..
    theBody=codesBean.replaceAll(theBody, "%%menu%%",ResourceBundle.getBundle("system").getString("Item_list"), true);
    instead of
    theBody=codesBean.replaceAll(theBody, "%%menu%%",blocksBean.menu(QueryValue,request.getContextPath()), true);
    This doesn't work because ResourceBundle.getBundle("... returns the value.. which is a string "blocksBean.menu(QueryValue,request.getContextPath())". But what I need is it has to be executed..
    blocksBean.menu() returns a string value of html code fetched from the dartabase.
    Is there a way I can execute blocksBean.menu() which is retrieved from the .properties file.. If anyone has done it / have an idea on this.. please e-mail me [email protected]
    I need something like an eval() in javaScript..
    Thanks in advance
    -ashok

    These boys might have something that will help you:
    http://www.beanshell.org/
    Good luck
    Lee

  • How can I read an XML string that's not from an XML file?

    I've got a script I'm trying to setup that communicates over a socket to retrieve different directions from a custom built Java program.  The Java program listens to requests from the Adobe scripting engine (in my case it's a Photoshop script) on a socket and immediately responds with the next set of directions.  These directions are currently in XML format.  The issue I'm having is that I can't parse the XML data since it's entered into a new XML object from a string rather than being read from a file.  Even without the socket code, you can see the issue by doing the following:
    var xml = new XML("<test><data>hey!</data></test>");
    alert(xml.test.data);
    alert(xml);
    The first alert "should" return "hey!" (without quotes, of course), but it doesn't, while the second alert returns what you would expect it to:
    <test>
        <data>hey!</data>
    </test>
    It works fine if read from an XML file, but from a string, like shown above, it just presents an empty alert box when attempting to access "xml.test.data".  Any ideas on how to fix this issue?  Can it be fixed?  Has it been fixed in newer versions (I'm currently using CS4)?
    Thanks in advance for any help!

    Duh... found my error... I was attempting to access the data by referencing the created "root" element.  Since <test> is the very first element tag, it's setup as the root element, which you don't need to reference.  Changing the alert to alert(xml.data); fixed it.
    Now I just feel dumb, lol...

  • I am adding itunes to a new computer and I do not want to use the back-up that is in icloud. How do I bypass icloud so i can add music from "My Music" file

    I am installing itunes on a new computer (Windows 8,1). I want to start fresh and would like to import my music from my music file and not from icloud. How do I make sure icloud doesn't automatically populate itunes on the new computer?

    Uncheck Edit > Preferences > Store > Show iTunes in the cloud purchases
    The correct way to move iTunes from one computer to another is to copy the ENTIRE iTunes folder from the old computer (or backup of the old computer) to the new computer.  This will make everything in iTunes on the new computer exactly as it was on the old computer.

  • Help:How to get a java String value from a C char array?

    Hi,everyone,could you help me?
    the following is a C struct that i want to recieve a short message:
    struct MO_msg{
    unsigned long long msgID;          //Message ID
    char      dest_id[21]; //Destination Mobile Phone Number
    char      service_id[10];     //
    Now I want to put the "dest_id " value of this struct into a Java String variable.But I dont know how to implement it!
    The following is a block of source code that i implement this functions.But it cant get a String value ,and throw out a Exception:
    java.lang.NullPointerException
    at java.lang.StringBuffer.append(StringBuffer.java:389)
    JNIEXPORT jint JNICALL Java_md_EMAP_thread_RubeMOTSSX_getMO
    (JNIEnv * env, jobject obj, jint connId, jobject mo){
         struct MO_msg MO;
         tssx_cmpp_api_debug_flag = 1;
         int result = CMPP_Get_MO((int)connId,&MO);
         if (result == 0){
              jclass cls = (*env)->GetObjectClass(env,mo);
              jfieldID msgId = (*env)->GetFieldID(env,cls,"msgId","J");
              jfieldID dest_Id = (*env)->GetFieldID(env,cls,"dest_Id","Ljava/lang/String;");
              jfieldID serviceId = (*env)->GetFieldID(env,cls,"serviceId","Ljava/lang/String;");          
              (*env)->SetLongField(env,mo,msgId,MO.msgID);               
              (*env)->SetCharField(env,mo,dest_Id,*destId);
              (*env)->SetCharField(env,mo,serviceId,MO.service_id);
         return result;
    Please help me!Thanks!

    bschauwe:Thank you for your help!
    Yes,just as you say,using NewString Or NewStringUTF can import a C char array into a Java String variable! But now I have another question,when i use these two functions ,i found that it cant deal with Chinese character!
    do you have such experiences to deal with another language charset?if you have ,can you tell me how to deal with it.

  • How to populate a java script array from a bean.

    Hi all,
    I have a list "mdfProductNames" which is further comprising of two fields "subGroup" and "mdfProductName"
    The list is coming is a part of the form bean.(struts framework)
    Now i want to have the values of these two fields in two different java script arrays.
    i.e. Array x -> mdfProductName
    and Array y -> subGroup
    can someone give me any idea as to how to do this ?
    Thanks
    Edited by: Ramit on 17 Jul, 2008 9:53 AM

    hi,
    assuming u use jstl, u need to create javascript variable during html generation out of the values got from struts form bean. it could look like this:
    ------ .jsp file ----
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <script type="text/javascript">
    var X = [];
    var Y = [];
    <c:forEach items="${formBeanName.mdfProductNames}" var="grpProdName">
    X.push( '${grpProdName.mdfProductName}' );
    Y.push( '${grpProdName.subGroup}' );
    </c:forEach>
    // here u already have the two arrays filled up with data
    </script>
    ------- end of .jsp file
    "formBeanName" is a name of a formbean u use to store the list of your beans
    rafal baton zaczynski
    http://baton.pop.e-wro.pl - tips and codes
    http://www.belysio.com - free mobile localization soft

  • How to set property "java.util.Arrays.useLegacyMergeSort" in jnlp-file?

    Hi,
    I have a problem in a web start application with java 7 and the new sort behavior (exception: comparison method violates its general contract).
    So I like to go back to previous behavior and tried to put the new java 7 system property "java.util.Arrays.useLegacyMergeSort" in the generated jnlp-File:
    <property name="java.util.Arrays.useLegacyMergeSort" value="true"/>.
    Now I can read the property value in java code with System.getProperty("java.util.Arrays.useLegacyMergeSort"), and guess the property was successful set, but the exception still appears?!
    The system property works with command line "javaws -J-Djava.util.Arrays.useLegacyMergeSort=true file.jnlp", but not via doubleclick on the jnlp-file or url and browser.
    Any ideas?
    Cheers,
    Dan

    Only "trusted" set of properties can be set in the JNLP file by unsigned applications.
    List of properties is revised from time to time but it usually takes time for new properties to be added to it (if there is strong demand for it as every property should undergo security audit).
    You can specify arbitrary property if you sign your application and JNLP file.

  • How to redirect "-verbose" Java Runtime Parameter setting to text file

    Simple question: I am adding a "-verbose" Java Runtime Parameter in the Java Applet Runtime Settings of the Java Control Panel. When I run my applet, a Windows console opens which outputs all the method calls, classes, and jar file information. How can I redirect this output to a text file?
    I noticed Xloggc:+filename+ but there does not seem to be an equivalent for redirecting the '-verbose' output to a file.
    Thanks!
    Edited by: zillius on Dec 14, 2007 1:47 PM

    Thank you both for the reply, but unfortunately that is not quite what I am looking for. The console Window I am talking about is a DOS console screen, not the Java Console
    What I am really after here is the ability to redirect a thread dump of a running applet to a text file. When the applet is active, and the "-verbose" parameter is set in the Java Runtime Parameters", I can see all the classes, methods etc. being loaded in the DOS window. Hitting Ctrl-Break at that point will produce a thread dump in the DOS console screen. I would like to be able to redirect THAT output to a text file. It is not in the Java Console. To me it looks like tracing and logging are only for the Java Console, no?
    Thanks again for your help.
    Edited by: zillius on Dec 19, 2007 7:17 AM

  • Anyone know how to Save an Java Image to gif or png file?

    I'm trying to build a Map Edito for game, I want to import some images which and a lot of tiles in each of them. I want to cut each tile 24x24 out, then save it in an invidual file.
    Anyone know how to save to file? any easy way?
    I know there is somehthing call JPEGEncoding to save into jpeg...
    thanks!

    Java Advanced Imaging does it nicely, take a look.
    I do not remember the extact syntax right now, but have used it in the past.

  • How to start a Java ADF application from Forms 10g

    Hi,
    I have a Java ADF application deployed to the OAS.
    How can I start the application from Forms 10g?

    By using the web.show_document forms built-in procedure... passing the web address of your ADF app as parameter.....
    Greetings...
    Sim

  • How to call a Java Web Service from another Java package ?

    Please, does anybody know a simple way to access to a JWSDP Web Service deployed under Tomcat with another java application ?
    I've tried with ServiceFactory and Service class from JaxRPC API but it doesn't work ....
    Thanx.

    What not just invoke it the same you would invoke a remote service? Create a service stub and call a service method.
    Mike

  • How to make the Java Logging to create the log file

    Hey,
    I need some help. Below is my code that create a log file for my application however, there is no log file being created when i perform a MarsLogger.log.info("test") in my code for my application.
    * LogManager.java
    * Created on April 10, 2006, 11:42 AM
    package comp1.mars.beans.ejb.util;
    import java.util.logging.*;
    import java.io.*;
    public class LogManager {
    /** Creates a new instance of LogManager */
    public LogManager() {
    protected static Logger getLogManager()
    //String dir = "C:/Sun03/studio5u1_se/appserver7/domains/domain1/server1/logs/an/my.log";
    String dir = "my.log";
    Logger logger = Logger.getLogger("compl1.mars.bean.ejb");
    try {
    // Create an appending file handler
    boolean append = true;
    FileHandler handler = new FileHandler(dir, append);
    //FileHandler(String pattern, int limit, int count, boolean append)
    // Add to the desired logger
    logger = Logger.getLogger("compl1.mars.bean.ejb");
    logger.addHandler(handler);
         logger.setLevel (Level.ALL);
    } catch (IOException e)
    e.printStackTrace();
    } catch(SecurityException se)
    se.printStackTrace();
    return logger;
    }//end of method
    }//end of class
    * MarsLog.java
    * Created on April 10, 2006, 3:24 PM
    package comp1.mars.beans.ejb.util;
    import java.util.logging.*;
    * @author Administrator
    public class MarsLogger extends LogManager {
    /** Creates a new instance of MarsLog */
    public MarsLogger() {
    public static Logger log= getLogManager();
    }

    What is the level of thte handler?
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/logging/Handler.html#setLevel(java.util.logging.Level)

  • How do we prevent uncaught exceptions in our web role from causing 502's across our entire service?

    We've recently migrated our web service to Azure. Part of it is running on an Azure Cloud Service. It serves around 5000 requests per minute, lots of dynamic image generation and various types of data feeds. We're currently running two Standard D4 instances
    backed by a P1 SQL database and B4 Redis cache.
    Our service is dependent on many 3rd party web services; try as we might sometimes bad data slips through the cracks and our service returns a 500 response (we output a short, custom xml response with usually an http 500 status). Occasionally this will happen
    to routes that receive many requests - large networks or devices that aggressively retry - and this appears to cause Azure to return a 502 error page for all routes to our web role. It doesn't even really take that many. A few thousand over a 15 minute period
    caused it today. It was simply an uncaught null reference exception.
    This takes our entire service down and is a huge issue for us. Is an Azure load balancer in front of our services canning our incoming connections when it detects some level of 500 responses from our service? What should we be doing differently?

    We're considering a couple of options. The first was simply to respond with a 503 response instead of a 500, and use the Retry-After header. We cannot guarantee clients will follow that header, however. Our other thought is to more closely monitor the error
    rate (currently we have a job checking every 5 minutes for the total errors per end point over the last 15 minutes) and when some low threshold is passed return a 200 response with a short message or an "empty" response appropriate to the expected
    content type (which might be a solid black image, for example).
    If feels wrong to return a 200 response when our service cannot successfully complete the request, but we're not sure what else to do and what Azure may or may not be doing that is outside of our control here.

Maybe you are looking for