I am trying to create a function within a Java Class that can execute a .exe or a .linux file during runtime. The program is espresso.exe (for Windows OS) and espresso.linux for (Linux based systems)
Typically, the way to run the program is by going to command line, and going to the folder in which the executable is stored and typing:
(in Command Prompt)
espresso A0.txt > m.txt
or espresso A0.txt (which returns the output in cmd)
(in linux Terminal)
./espresso.linux A0.txt > m.txt
or ./espresso.linux A0.txt (which returns the output in the terminal window)
Here A0.txt is the input argument and m.txt is the file that espresso creates.
I have stored A0.txt and espresso.linux and espresso.exe under a folder src/resources
I tried the following:
ProcessBuilder pb = new ProcessBuilder("./src/resources/espresso.exe","src/resources/A0.txt",">src/resources/m.txt");
try {
Process p = pb.start();
}catch (IOException ex) {
Logger.getLogger(NetSynth.class.getName()).log(Level.SEVERE, null, ex);
}
I also tried:
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("src/resources/espresso.linux src/resources/A0.txt > src/resources/m.txt");
int waitFor = p.waitFor();
Both of them fail to identify the file to be executed and do not run the command. I understand there may be many errors in the 2 approaches. I could use some help to figure out the approach and the code to be written to run the executable file.
Also, is there a path to be mentioned to run espresso.linux? Will /src/resources/espresso.linux suffice?
Thanks in advance.