I am trying to run an .exe from a java application, but I am getting this error message:
Java Virtual Machine Launcher(title) A Java Exception has occurred.
I have tried:
try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("C:\\PathToExe\\MyExe.exe");
InputStream in = p.getInputStream();
OutputStream out = p.getOutputStream();
InputStream err = p.getErrorStream();
} catch (Exception exc) {}
And:
try {
Process process = new ProcessBuilder("C:\\PathToExe\\MyExe.exe").start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException ex) {
Logger.getLogger(ScannerUI.class.getName()).log(Level.SEVERE, null, ex);
}
Both of them work when I try to run something else like uTorrent, but it fails when I try to run the .exe that I have to.
Also, this .exe is in a folder and if I try to run this .exe alone (out of it's folder) it returns the same error message.
I don't think the code above is wrong, but it's missing something to be able to run my .exe.
New CODE:
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("C:\\PathToExe\\MyExe.exe");
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Exception e)
{
e.printStackTrace();
}
New Output:
<ERROR>
Exception in thread "main" java.lang.NoClassDefFoundError: **org/lwjgl/LWJGLException**
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
</ERROR>
Process exitValue: 0