Runtime.exec fails to launch C++ application

A java application launches a C++ Windows based application, providing it with arguments on the command line. This application is supposed to start, to execute something and to exit.
This is working as long as the java code runs from the command prompt.
When the java code is running as part of a Java Windows 2000 service, the C++ application starts but enters a loop and never returns. It consumes all CPU and waits for something that I could not figure out. I can just see the process in the Task Manager.
Windows 2000 service is configured as loging on a user account.
I have not the code of the C++ application and cannot modify it.
Here is the piece of code that starts this C++ Application :
//Start the command and wait for completion
try{
java.lang.Process submitProcess = Runtime.getRuntime().exec(command);
submitProcess.waitFor();
if(submitProcess.exitValue() == 0){
return;
} else{
System.out.println("exitValue = " + submitProcess.exitValue());
} catch(Exception e){e.printStackTrace();

For information, wrapping input and error streams did not return any information.
Doing further testing, I found that this application - a viewer that I use for its command line print functionality- starts looping when I pass as argument a DWG file. If I ask it to print .DOC or .XLS or .HTML ... files, it works.
If I start the application from Java code at command prompt, it works even with this DWG file and it does not ask for anything.
My conclusion is that the loop comes from a component used for Autocad conversion when the Java code launching the application is started as Windows 2000 service.

Similar Messages

  • Runtime.exec() fails sometime to execute a command

    Hello,
    I have a program thats using Runtime.exec to execute some external programs sequence with some redirection operators.
    For e.g, I have some command as follows;
    1 - C:\bin\IBRSD.exe IBRSD -s
    2 - C:\bin\mcstat -n @punduk444:5000#mc -l c:\ | grep -i running | grep -v grep |wc -l
    3 - ping punduk444 | grep "100%" | wc -l
    ...etc.
    These command in sequence for a single run. The test program makes multiple such runs. So my problem is sometimes the runtime.exec() fails to execute some of the commands above (typically the 2nd one). The waitFor() returns error code (-1). That is if I loop these commands for say 30 runs then in some 1~4 runs the 2nd command fails to execute and return -1 error code.
    Can some one help me out to as why this is happening? Any help is appreciated
    Thanks,
    ~jaideep
    Herer is the code snippet;
    Runtime runtime = Runtime.getRuntime();
    //create process object to handle result
    Process process = null;
    commandToRun = "cmd /c " + command;
    process = runtime.exec( commandToRun );
    CommandOutputReader cmdError = new CommandOutputReader(process.getErrorStream());
    CommandOutputReader cmdOutput = new CommandOutputReader(process.getInputStream());
    cmdError.start();
    cmdOutput.start();
    CheckProcess chkProcess = new CheckProcess(process);
    chkProcess.start();
    int retValue = process.waitFor();
    if(retValue != 0)
    return -1;
    output = cmdOutput.getOutputData();
    cmdError = null;
    cmdOutput = null;
    chkProcess = null;
    /*******************************supporting CommandOutputReader class *********************************/
    public class CommandOutputReader extends Thread
    private transient InputStream inputStream; //to get output of any command
    private transient String output; //output will store command output
    protected boolean isDone;
    public CommandOutputReader()
    super();
    output = "";
    this.inputStream = null;
    public CommandOutputReader(InputStream stream)
    super();
    output = "";
    this.inputStream = stream;
    public void setStream(InputStream stream)
    this.inputStream = stream;
    public String getOutputData()
    return output;
    public void run()
    if(inputStream != null)
    final BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream), 1024 * 128);
    String line = null;
    try
    while ( (line = bufferReader.readLine()) != null)
    if (ResourceString.getLocale() != null)
    Utility.log(Level.DEBUG,line);
    //output += line + System.getProperty(Constants.ALL_NEWLINE_GETPROPERTY_PARAM);
    output += line + "\r\n";
    System.out.println("<< "+ this.getId() + " >>" + output );
    System.out.println("<< "+ this.getId() + " >>" + "closed the i/p stream...");
    inputStream.close();
    bufferReader.close();
    catch (IOException objIOException)
    if (ResourceString.getLocale() != null)
    Utility.log(Level.ERROR, ResourceString.getString("io_exeception_reading_cmd_output")+
    objIOException.getMessage());
    output = ResourceString.getString("io_exeception_reading_cmd_output");
    else
    output = "io exeception reading cmd output";
    finally {
    isDone = true;
    public boolean isDone() {
    return isDone;
    /*******************************supporting CommandOutputReader class *********************************/
    /*******************************supporting process controller class *********************************/
    public class CheckProcess extends Thread
    private transient Process monitoredProcess;
    private transient boolean continueLoop ;
    private transient long maxWait = Constants.WAIT_PERIOD;
    public CheckProcess(Process monitoredProcess)
    super();
    this.monitoredProcess = monitoredProcess;
    continueLoop =true;
    public void setMaxWait(final long max)
    this.maxWait = max;
    public void stopProcess()
    continueLoop=false;
    public void run()
    //long start1 = java.util.Calendar.getInstance().getTimeInMillis();
    final long start1 = System.currentTimeMillis();
    while (true && continueLoop)
    // after maxWait millis, stops monitoredProcess and return
    if (System.currentTimeMillis() - start1 > maxWait)
    if(monitoredProcess != null)
    monitoredProcess.destroy();
    //available for garbage collection
    // @PMD:REVIEWED:NullAssignment: by jbarde on 9/28/06 7:29 PM
    monitoredProcess = null;
    return;
    try
    sleep(1000);
    catch (InterruptedException e)
    if (ResourceString.getLocale() != null)
    Utility.log(Level.ERROR, ResourceString.getString("exception_in_sleep") + e.getLocalizedMessage());
    System.out.println(ResourceString.getString("exception_in_sleep") + e.getLocalizedMessage());
    else
    System.out.println("Exception in sleep" + e.getLocalizedMessage());
    if(monitoredProcess != null)
    monitoredProcess.destroy();
    //available for garbage collection
    // @PMD:REVIEWED:NullAssignment: by jbarde on 9/28/06 7:29 PM
    monitoredProcess = null;
    /*******************************supporting process controller class *********************************/

    Hi,
    Infact the command passed to the exec() is in the form of a batch file, which contains on of these commands. I can not put all commands in one batch file due to inherent nature of the program.
    But my main concern was that, why would it behave like this. If I run the same command for 30 times 1~3 times the same command can not be executed (returns with error code 1, on wiun2k pro) and rest times it works perfectly fine.
    Do you see any abnormality in the code.
    I ahve used the same sequence of code as in the article suggested by
    "masijade". i.e having threads to monitor the process and other threads to read and empty out the input and error streams so that the buffer does not get full.
    But I see here the problem is not of process getting hanged, I sense this because my waitFor() returns with error code as 1, had the process hanged it would not have returned , am I making sense?
    Regards,
    ~jaideep

  • Runtime.exec() fails to run "javac" with "*.java" as arguments

    Hello,
    I am observing that Runtime.exec() consistently fails to execute "javac" when the Java files to be compiled are specified as "*.java". It fails with the following error:
    javac: file not found: /home/engine931/*.java
    Usage: javac <options> <source files>
    The same command used for Runtime.exec() runs fine from a the command shell. Is this is known problem with the Runtime class on UNIX, because it works fine on Windows.
    Any advise is appreciated.
    Thanks,
    Ranjit

    Your shell is expanding the command when you run javac from the shell. Try constructing your Runtime parameters so that your shell is executed, which then executes javac.
    The specific behavior is entirely dependent on the command interpreter that's used.

  • Runtime.exec() fails

    Hi,
    I have a process with many executables which work together to copy a script to another machine, execute it and get back the results. I am using Runtime.exec to execute the process. The files are stored in the directory "/opt/mx/myDir".
    Below are two scenarios. One works and the other doesnt.
    1. Working case.
    #cd /opt/mx/myDir
    #java myJavaClass.
    2. Failing case.
    #java myJavaClass.
    The issue is that myJavaClass is part of another project and hence I cannot "cd" to /opt/mx/myDir. So it executes at some directory and fails.
    Hence I tried ProcessBuilder.directory(file) - This fails too.
    I have no logs or anything as the other process is not mine.
    Any help on debugging this will be great.
    Thanks.

    Apologies if this is too obvious, but is your command
    #java myJavaClass.
    or
    java myJavaClass
    The trailing period is wrong.

  • Failed to launch JavaFX application with native bundle exe

    Hi,
    I have created a JavaFX application, and created its native bundle using Ant. When I am trying to launch application using Jar from bundle created with double click, it successfully launching my application. But when I am trying double click on MyApplication.exe (say), it throwing JavaFX Launcher Error *"Exception while running Application"*.
    I have searched about this issue, I found about jre, so I did replace jre from *"C:\Program Files\Java\jdk1.7.0_10\jre"* to my application bundle folder -- *\bundles\MyApplication\runtime\jre*, then I tried to launch exe with double click, it successfully launched.
    I have compared both jre, there are many missing jar, exe, dll and some properties files I found.
    I have these environment settings -
    JAVA_HOME -- C:\Program Files\Java\jdk1.7.0_10
    JREFX_HOME -- C:\Program Files\Oracle\JavaFX 2.2 Runtime
    Path contains an entry of C:\Program Files\Java\jdk1.7.0_10\bin JAVA_HOME and JREFX_HOME are used as in my build.xml to take ant-javafx.jar and jfxrt.jar --
    ${env.JAVA_HOME}/lib/ant-javafx.jar
    ${env.JREFX_HOME}/lib/jfxrt.jarMy steps to create bundle are -
    <target name="CreatingExe" depends="SignedJar">
                 <fx:deploy width="800" height="600" nativeBundles="all" outdir="${OutputPath}" outfile="${app.name}">
                          <fx:info title="${app.title}"/>
                          <fx:application name="${app.title}" mainClass="${main.class}"/>
                          <fx:resources>
                               <fx:fileset dir="${OutputPath}" includes="*.jar"/>
                         <fx:fileset dir="${WorkingFolder}/temp"/>
                   </fx:resources>
               </fx:deploy>
    </target>What more needed in build.xml so that application launch correctly with exe ?
    Thanks

    You code is not dealing with the DACL access to Winsta0\Default.  Only the LocalSystem account will have full access and the interactively logged on user which is why regedit is not displaying properly.  You'll need to grant access to your user. 
    You also need to deal with UAC since that code is going to give you a non-elevated token via LogonUser().  You need to get the full token via a call to GetTokenInformation() + TokenLinkedToken.
    thanks
    Frank K [MSFT]
    Follow us on Twitter, www.twitter.com/WindowsSDK.

  • Runtime.Exec() fails -- Through java stored procedure in Oracle8i

    HI,
    I HAVE A JAVA STORED PROCEDURE WHICH EXECUTES
    A HOST COMMAND USING Runtime.Exec().
    BUT IT IS NOT WORKING.
    RIGHTS FOR THE USER HAVE BEEN GIVEN USING
    Dbms_grant_persmission(). The database in on
    SUN SOLARIS. THE EXITVALUE OF THE RUNTIME.EXEC COMMAND IS 255(SEGMENTATION
    ERROR - CORE DUMPED).
    PLEASE LET ME KNOW WHERE THE PROBLEM LIES. THE FUNCTION IS WORKING WELL IF THE DATABASE IS ON NT PLATFORM BUT FAILS TO WORK WHEN I STORED THE PROCEDURE IN A DATABASE RUNNING ON SUN SOLARIS AND TRIED TO EXECUTE A SOLARIS COMMAND THROUGH THE PROCEDURE.
    Thanks for ur interest!
    with best regards,
    Mathan

    I have similar problem on HP-UX, I would appreciate if you
    somehow were able to solve it.
    Thanks
    Rahul Shah

  • Runtime#exec() from within a J2EE application

    I've got a batch processing task running on a timer as part of my J2EE application on WebLogic 8.1 and I'm experiencing problems with invoking Runtime#exec().
    To be more accurate, this is what I'm trying to do:
    * Moves a file in the filesystem using native shell commands.
    * @param src The file to move.
    * @param dst The destination file.
    public void move(String src, String dst) {
        Runtime runtime = Runtime.getRuntime();
        Process p = runtime.exec(new String[] { "mv", "-f", src, dst });
    }Now, this piece of code works perfectly when run manually ("java Move foo.txt bar.txt") but when it's run within the J2EE application -- as the same user as in the manual case -- the file's won't get moved anywhere.
    I suppose it's a permission/policy issue. If that's the case, how should I edit the policy file?
    I already tried to add the following lines to weblogic.policy:
    grant codeBase "file:${user.domain}/myServer/.internal/-" {
      permission java.security.AllPermission;
    grant codeBase "file:${user.domain}/myServer/.wlnotdelete/-" {
      permission java.security.AllPermission;
    };...but that didn't seem to help at all.

    Ok. I managed to solve this one by myself. The solution was to read the "stdout" and "stderr" streams from the process.
    Any idea why reading the streams helped?

  • Runtime exec fail()

    I exec() an shell script, which is not executable. I would like to know how can I handle the exception. I would like to use the getErrorStream() when there is an error. I do not know how do I set it up?
    Thanks

    From the Runtime.exec documentation:
    Starting an operating system process is highly system-dependent. Among the many things that can go wrong are:
    The operating system program file was not found.
    Access to the program file was denied.
    The working directory does not exist.
    In such cases an exception will be thrown. The exact nature of the exception is system-dependent, but it will always be a subclass of IOException.
    Catch and handle the exception. Follow the methods in this tutorial:
    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

  • Runtime.exec() causes app to hang

    Hello all, I'm having an issue with the Runtime.exec() and I'm hoping someone in the forum can shed some light on it for me.
    My application currently includes the capability for my end users to run a variety of reports, all of which are written in SQR (BRIO reporting language). Since my application is in Java ( and all the reports were written for a previous application), I use the Runtime.exec() call to launch the SQR viewer application. The problem I'm having is this: When I run the code below in my development environment (using a front end framework from Oracle (JDeveloper)), everything works fine. When I deploy my application to a jar file, the application runs fine until the code below is called. At this point the application hangs terribly and my CPU usage is maxed out by my app. The process for the report is created but is unable to garner the necessary resources to run because my application is using them all. If I kill my application, the report process then runs as expected.
    Why would the same code run fine in development but not when deployed to a jar file?
    The following is the code in question:
        try {
          Runtime rt = Runtime.getRuntime();
          Process proc = rt.exec(sDrive + "\\SQR6\\SQRW " + sDrive + "\\SQR6\\REPORTS\\" + repName + ".SQT " + sConn + " -RT -FC:\\SPL\\ -C -ZIV");
          InputStream stderr = proc.getErrorStream();
          InputStreamReader isr = new InputStreamReader(stderr);
          BufferedReader br = new BufferedReader(isr);
          String line = null;
          while ( (line = br.readLine()) != null)
            System.out.println(line);
          int exitVal = proc.waitFor();
        catch (Throwable ie)
          ie.printStackTrace();
        }    All thoughts and suggestions are welcomed.
    Thanx in advance,
    eribs4e

    So you either tried adding a reader for stdout, or you're sure that nothing is produced on stdout? And you're sure it's not expecting anything on stdin?
    You say your app runs fine up to that code, and then eats all the CPU right? Sounds like a spin lock. One possibility is that it's something like this: br = bufferedReaderForStdOut;
    while ( (line = br.readLine()) != null)
            System.out.println(line);
    while ((line = br.readLine() == null); Not that I expect that you have precisely that in your code, but I suspect the problem may actually be a spin-lock that precedes the code you've posted. I don't see anything obviously wrong with what you have, so if there's a problem in your code, it's probably in what you haven't shown.

  • Runtime.exec() with japanese arguments?

    I'm trying to invoke a C++ executable from java using the Runtime.exec() method. The C++ application accepts a filename as a command line argument & opens the file. This C++ app is unicode enabled i.e. it can accept UTF-16 (wide char) parameters. Howevere, when i invoke this application using Java's Runtime.exec() and specify a japanese file name as an argument, the japanese characters get converted to '?' characters by the time they are received in the C++ application. I'm running this application on Windows 2K, default i.e. English version.
    Looking at the source code of Runtime class, it seems that the exec()
    function makes use of a native helper function - execInternal(). Does
    this function support the entire unicode range?
    Is there any way we can avoid the conversion of japanese characters to '?' characters? Also, is there any other alternative for invoking an external application with Unicode (Say, japanese) arguments?
    Please reply ASAP.
    Thanks!

    I have a very similar problem. I am invoking cvs through Runtime.exec, and I am using it to add and check in files with chinese characters in the name, and it is failing with the following cvs error:
    Could not add resource file &#32435;&#20986; in directory C:\test to repository: cvs add: nothing known about ??
    The error message comes from cvs, and I have been able to track it down to the call string I pass to exec. It is correct when passed in but the command fails. For laughs I tried to call something simpler, like mkdir:
    err mkdir ?? is: The filename, directory name, or volume label syntax is incorrect.
    It seems pretty clear to me that although the callstring is correct, the call to exec fails, and the special characters are replaced with questionmarks, which seems to me to be an encoding issue.
    Did you get any solution to your problem, or does anyoen else have an answer for this?

  • Runtime exec opens new window

    Hi, I am using Runtime.exec to run an external application in Windows2000. � can read its output and i can destroy it without any problems.
    But when i run my java application with javaw , the external application i run with rt.exec opens new window(without output texts, empty) . just output command windows which opens when i run the external app. from a command prompt.
    If i run my java application with java.exe then then external application DO NOT open new window and run correctly. But this time my java window stays on desktop, and that's not any good for a Windows Application.
    In both cases everything runs OK. The only problem is the command prompt windows.
    Is there a solution when working with javaw.exe ? or hide the window when running with java.exe
    Thanks all.

    bug with ID: 4244515

  • Runtime.exec() does not work?

    I'm trying to invoke a C++ executable from java using the Runtime.exec() method. The C++ application accepts a filename as a command line argument & opens the file. This C++ app is unicode enabled i.e. it can accept UTF-16 (wide char) parameters. Howevere, when i invoke this application using Java's Runtime.exec() and specify a japanese file name as an argument, the japanese characters get converted to '?' characters by the time they are received in the C++ application. I'm running this application on Windows 2K, default i.e. English version.
    Looking at the source code of Runtime class, it seems that the exec()
    function makes use of a native helper function - execInternal(). Does
    this function support the entire unicode range?
    Is there any way we can avoid the conversion of japanese characters to '?' characters? Also, is there any other alternative for invoking an external application with Unicode (Say, japanese) arguments?
    Please reply ASAP.
    Thanks!

    >
    I'm trying to invoke a C++ executable from java using
    the Runtime.exec() method. The C++ application accepts
    a filename as a command line argument & opens the
    file. This C++ app is unicode enabled i.e. it can
    accept UTF-16 (wide char) parameters. Howevere, when i
    invoke this application using Java's Runtime.exec()
    and specify a japanese file name as an argument, the
    japanese characters get converted to '?' characters by
    the time they are received in the C++ application. I'm
    running this application on Windows 2K, default i.e.
    English version.
    Looking at the source code of Runtime class, it seems
    that the exec()
    function makes use of a native helper function -
    execInternal(). Does
    this function support the entire unicode range?I don't know because I've never tested this case specifically.
    You didn't show your code though. How are you reading in the String? You mentioned that you passed a Japanese character String as a filename argument. I also read that you are running on an English Win2K platform. How did you read that argument in? It may just be that you read the argument in your default encoding(English) and you needed to specify an alternate one.

  • Runtime.Exec for 'appref.ms' files

    Hello!
    I am using Runtime.exec to call an external application from java classes. These classes are in turn used by JSP.
    The external application is an "Application Reference" type application in Windows, and has the extension appref.ms
    From Glassfish logs, I can see the following error:
    java.io.IOException: Cannot run program ""C:\Documents and Settings\Administrator\Start Menu\Programs\ProTeleCo\QuotEncrypt.appref-ms"": CreateProcess error=193, %1 is not a valid Win32 application
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
        at java.lang.Runtime.exec(Runtime.java:593)
        at java.lang.Runtime.exec(Runtime.java:466)
        at list.CreateNew.runExternal(CreateNew.java:251)
        at list.CreateNew.CreateQuotationDR(CreateNew.java:222)
        at list.CreateNew.processRequest(CreateNew.java:88)
        at list.CreateNew.doPost(CreateNew.java:143)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
    Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
        at java.lang.ProcessImpl.start(ProcessImpl.java:30)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
        ... 35 moreWhen I open a command window and type
    "C:\Documents and Settings\Administrator\Start Menu\Programs\MyCompany\QuotEncrypt.appref-ms" <arg1> <arg2>
    The program runs without problems.
    I actually tried copying the QuotEncrypt.exe file that is built in the development environment to the server and give that as argument to Runtime.exec, but in that case the application seems to run (I use waitfor and the return value from waitfor) , return with 0, but it has no side effects. It does not even write to its log file.
    Hence I am at a loss to what to do.
    Appreciate any help,
    Irem

    And now the program hangs.
    It seems to be time for code indeed:
    String[] commands = {"C:\\WINDOWS\\system32\\cmd.exe", " /start ", Constants.QuotEncryptPath, " \""+qfile + "\"", Constants.encryptPassword};
      runExternal(commands);
          public static void runExternal(String commands[])
            try
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing ");
                String whole="";
                for(int i =0; i < commands.length ; i ++)
                whole = whole + commands;
    System.out.println(whole);
    Process proc = rt.exec(commands);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
    import java.io.*;
    import java.util.*;
    * @author iaktug
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    @Override public void run()
    try
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    I got the code from the famous when Runtime.exec() won't. I am now suspecting there is something wrong with this part.
    Essentially I want a very simple thing. The external program will run and the parent program will wait for it and get the return value.
    I added the Stream stuff simply to prevent deadlock/hanging.
    I am considering trying to get that out completely.
    The server messages go as follows:....
    Execing |#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878233;_ThreadName=httpSSLWorkerThread-8082-4;|
    C:\WINDOWS\system32\cmd.exe /start "C:\Documents and Settings\Administrator\Start Menu\Programs\ProTeleCo\QuotEncrypt.appref-ms" "H:\QUOTATIONS\Quotations\In Progress\q00502.xls"1q2w3e|#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
    OUTPUT>Microsoft Windows [Version 5.2.3790]|#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
    OUTPUT>(C) Copyright 1985-2003 Microsoft Corp.|#]
    [#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
    OUTPUT>|#]

  • Runtime.exec opens up new Window

    Hi, I am using Runtime.exec to run an external application in Windows2000. � can read its output and i can destroy it without any problems.
    But when i run my java application with javaw , the external application i run with rt.exec opens new window(without output texts, empty) . just output command windows which opens when i run the external app. from a command prompt.
    If i run my java application with java.exe then then external application DO NOT open new window and run correctly. But this time my java window stays on desktop, and that's not any good for a Windows Application.
    In both cases everything runs OK. The only problem is the command prompt windows.
    Is there a solution when working with javaw.exe ? or hide the window when running with java.exe
    Thanks all.

    When you use javaw, then the dos window that pops up is no longer needed, and you can close it manually and the java program will still run.
    To avoid this dos window, make a bat file to start your application. I guess you already do that, but make it this way
    start javaw ....
    exitI'm not sure if exit is necessary but I included it just to make sure it works.

  • Runtime().exec() -- launching an application

    Hello again,
    I've got a hopefully simple question.
    I would like to launch a program, yEd Graph Editor to be exact, from my java application.
    I'm working on unix.
    I have read most of the much sited guide here http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html however I'm not quite to that point yet, and his discussion most closly related to my inquiry is with respect to Windows.
    From that guide I ran a piece of his code:
            try
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("javac");
                int exitVal = proc.waitFor();
                System.out.println("Process exitValue: " + exitVal);
            } catch (Throwable t)
                t.printStackTrace();
              }This ran, no problems.
    So I thought why can't I just change the name of the file to be executed?
    I tried switching the "javac" to "yed", which is the name of the file were I to run it from the command console.
    However, I get the error:
    java.io.IOException: java.io.IOException: No such file or directory
       at java.lang.ConcreteProcess.<init>(libgcj.so.7)
       at java.lang.Runtime.execInternal(libgcj.so.7)
       at java.lang.Runtime.exec(libgcj.so.7)
       at java.lang.Runtime.exec(libgcj.so.7)
       at java.lang.Runtime.exec(libgcj.so.7)
       at CreateGML.main(CreateGML.java:10)
    Caused by: java.io.IOException: No such file or directory
       at java.lang.ConcreteProcess.nativeSpawn(libgcj.so.7)
       at java.lang.ConcreteProcess.spawn(libgcj.so.7)
       at java.lang.ConcreteProcess$ProcessManager.run(libgcj.so.7)If anyone has any suggestions on how to fix this, or if I'm doing something blatently wrong(likely T_T) please let me know.
    Also, once I've got this application open is it possible to load a file into it?
    Like opening Adobe Acrobat and then opening a pdf into it?
    I've seen, to use the pdf example, people just opening pdfs, which automatically open Acrobat. Unfortunatly, I do not have that option in this case as far as I know.
    Thanks again!

    Hello,
    javac is either in /usr/bin or /usr/sbin and in your searchpath, yed is not:
    // ln -s /usr/....bin/yed /usr/bin/yedIf this does not help, try to use the absolute path to its binary.
    You can tell the applications you want to execute, to open a file only if these application support command line arguments. e.g. Firefox does support them, and so does Gimp, OpenOffice.org and so on.
    just try it in the console (xterm, or similar).
    Regards,
    Florian
    Edit: btw: if you open a pdf file in windows, the entered application gets started automatically. Maybe, but only "maybe" it is possible to chmod +x and then start other files on linux likewise, but I am not that sure if it works.
    Edited by: fbrunner on Jul 2, 2008 6:11 PM
    Edited by: fbrunner on Jul 2, 2008 6:13 PM

Maybe you are looking for

  • Need help deleting unused swatches in CS4

    I upgraded from CS3 to CS4, and simultaneously switched platforms from windows to mac osx. Now I can't find the option for deleting all unused swatches in the swatch palette menu and I'm starting to feel insane because I've run several searches and n

  • LOST file sharing  with Leopard update

    BIg bummer: after Leopard update from OS 5.4.11, I lost file sharing on ethernet to my G4 (running OS 9.2.2). It was so easy to set up and access the G4 on Tiger. Now it's impossible. HELP HELP

  • How to include Time delay in GUI enviroment

    hi all, i want to include time delay while drawing the shapes in the Canvas. I tried with Thread.sleep() and also delaying methods by making them to loop for large number of times.... but it affects the repainting of my Frame window like just previou

  • How do I move images from my external back to my computer?

    Approx. 6-7 months ago I moved all my images to my external hard drive and worked from there.  I've since upgraded to a much larger internal hard drive and want to move them back.  I intially moved them via finder and Lightroom would say that the ima

  • Flash content activating IE controls

    I am having difficulty with flash inserts in my pages activating IE controls and messing up the appearance of my page. What can I do to offset the presence of flash in my pages activating these controls in IE? Help please. Thanks