-
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.
-
Never ever swallow possible exceptions with
Code:
catch(Exception e){
}
at least print the stack trace.
-
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:
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:
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:
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.
-
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!
-
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.
-
-
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 ???