Results 1 to 7 of 7
  1. #1
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default Executing .exe from java

    I have an executable (luxconsole.exe) that i want to run from within java, with an argument of a file path/name.

    This is what i have:
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("C:\\Documents and Settings\\hgaddipa\\Desktop\\lux\\luxconsole.exe -00001.lxs");
    BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream()));
    OutputStream outt = p.getOutputStream ();
    InputStream err = p.getErrorStream() ;
    boolean done = false;
    while(done == false){
    if(input.readLine().contains("100%") == true){
    done = true;
    System.out.println(files[i].toString()+" Done.");
    }
    }
    }
    catch(Exception e){

    }

    the .lxs is the argument (file name).

    whats wrong with it? Nothing is happening.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Never ever swallow possible exceptions with
    Java Code:
    catch(Exception e){
    
    }
    at least print the stack trace.

  3. #3
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    I am not getting any exception. Here are more details.

    I have a exe file (luxconsole.exe), and when used in command line, it is used like this:
    Java Code:
    C:/path/to/exe/luxconsole.exe C:/path/to/file/file.lxs
    From java, i have theese variables:

    luxpath - the location of luxconsole.exe
    filepath - file location
    file[i] - file name from an array, where i is variable of for loop

    I am trying to execute this like this:

    Java Code:
    Runtime rt = Runtime.getRuntime();
                    String[] cmd = {luxpath+"luxconsole.exe"," "+filepath+files[i]};
                    Process p = rt.exec(cmd);
    However, nothing happens when executing.

    Sn example of paths:

    luxpath = E:\
    filepath = E:\testanim\
    file[i] = -00001.lxs

    Also, how do i recieve the output of the command, like the echo in command line after starting something? I tried this:


    Java Code:
     BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream()));
                     OutputStream outt = p.getOutputStream ();
                     InputStream err = p.getErrorStream() ;
                     String msg = "";
                     boolean done = false;
                     while(done == false){
                         if((msg = input.readLine()) != null){
                             System.out.println(msg);
                         if(input.readLine().contains("100%") == true){
                             done = true;
                             System.out.println(files[i].toString()+" Done.");
                         }
                         }
                     }
    But either the executing didnt work and isnt returning anything, or the code is wrong.

    Thanks.

    EDIT: On a side note, how do update the output of a text area on the GUI? I am using output.append, but it wont update until everything is done.
    Last edited by rp181; 09-21-2009 at 03:02 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,776
    Rep Power
    25

    Default

    If there is a println() in the catch Exception clause that is not printing, is there any output to the ErrorOutput stream?

    Is there an exitValue() from the Process?

    What does luxconsole.exe do? Just read a file and print some output? No reading!

  5. #5
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    Yes, there is a println statement, but nothing coming out of it. Luxconsole is a renderer (Computer Graphics). When it is done, it returns a statement 100% done. While rendering, it outputes a status every few seconds.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Read this article.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,776
    Rep Power
    25

    Default

    To verify your java code, have you tried it with a simple DOS program that prints a few lines and exits? When that works, try with your program and its data in the same folder with the java program. Then use the paths to the executable and its data.

    You didn't say if there is any output to the Error Stream ???

Similar Threads

  1. Executing java program using windows scheduler
    By kanitha in forum New To Java
    Replies: 0
    Last Post: 03-21-2009, 10:16 AM
  2. Executing an external java program
    By arunsubramanian in forum Advanced Java
    Replies: 5
    Last Post: 02-06-2009, 08:49 AM
  3. Porblem Executing Queries in Java
    By ajit.mishra@gs.com in forum New To Java
    Replies: 1
    Last Post: 09-05-2008, 08:31 AM
  4. [SOLVED] executing java over network
    By jmHoekst in forum New To Java
    Replies: 6
    Last Post: 06-30-2008, 06:58 PM
  5. executing the java file
    By TheBayWatchMan in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •