Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 1254 characters in body
Source Link
Hovercraft Full Of Eels
  • 285.8k
  • 25
  • 268
  • 391

You need to call the jar with java.exe, and you're not doing that. Also you need to trap the input and error streams from the process, something you can't do the way you're running this. Use ProcessBuilder instead, get your streams and then run the process.

For example (and I can only do a Windows example),

import java.io.IOException; import java.io.InputStream; import java.util.Scanner; public class ProcessEg { private static Process p; public static void main(String[] args) { String[] commands = {"cmd", "/c", "dir"}; ProcessBuilder pBuilder = new ProcessBuilder(commands); pBuilder.redirectErrorStream(); try { p = pBuilder.start(); InputStream in = p.getInputStream(); final Scanner scanner = new Scanner(in); new Thread(new Runnable() { public void run() { while (scanner.hasNextLine()) { System.out.println(scanner.nextLine()); } scanner.close(); } }).start(); } catch (IOException e) { e.printStackTrace(); } try { int result = p.waitFor(); p.destroy(); System.out.println("exit result: " + result); } catch (InterruptedException e) { e.printStackTrace(); } } } 

You need to call the jar with java.exe, and you're not doing that. Also you need to trap the input and error streams from the process, something you can't do the way you're running this. Use ProcessBuilder instead, get your streams and then run the process.

You need to call the jar with java.exe, and you're not doing that. Also you need to trap the input and error streams from the process, something you can't do the way you're running this. Use ProcessBuilder instead, get your streams and then run the process.

For example (and I can only do a Windows example),

import java.io.IOException; import java.io.InputStream; import java.util.Scanner; public class ProcessEg { private static Process p; public static void main(String[] args) { String[] commands = {"cmd", "/c", "dir"}; ProcessBuilder pBuilder = new ProcessBuilder(commands); pBuilder.redirectErrorStream(); try { p = pBuilder.start(); InputStream in = p.getInputStream(); final Scanner scanner = new Scanner(in); new Thread(new Runnable() { public void run() { while (scanner.hasNextLine()) { System.out.println(scanner.nextLine()); } scanner.close(); } }).start(); } catch (IOException e) { e.printStackTrace(); } try { int result = p.waitFor(); p.destroy(); System.out.println("exit result: " + result); } catch (InterruptedException e) { e.printStackTrace(); } } } 
Source Link
Hovercraft Full Of Eels
  • 285.8k
  • 25
  • 268
  • 391

You need to call the jar with java.exe, and you're not doing that. Also you need to trap the input and error streams from the process, something you can't do the way you're running this. Use ProcessBuilder instead, get your streams and then run the process.