I want to execute an external .exe program from inside Java. .Exe is a CLI application that receives data at runtime (scanf ()) and displays it depending on the input. I can call a program to execute from Java using
Process p = Runtime.getRuntime().exec("cmd /c start a.exe");
instead
Process p = Runtime.getRuntime().exec("cmd /c start a.exe");
But I think that you can also call the program from within Java. I have the whole program written in C ++, I just need a graphical interface written in Java. There are several things worth paying attention to: =
1) Communication with .exe should be performed at runtime (not via main (args)). 2) The Java program should receive the output and save it in some variable / panel for future use. 3) The program that should be executed may be different (for example, the user can choose .exe, which does not accept any data at all) ........ Thus, basically the Java GUI will act as RuntimeEnv
public void runEXE()
{
String s = null;
try {
Process p = Runtime.getRuntime().exec("cmd /c a.exe");
System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
I know that there are many questions on this topic. But I can not find any of them very useful.
source
share