javatextfieldexternal-process

Run external program with custom argumets


I am trying to run an external program with custom arguments placed in text field.

Here is my code:

String customPARAM = textfield.getText();
try {
    new ProcessBuilder("MyEXE.exe", "-param1 " + customPARAM).start();
} catch (IOException ex) {
    Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}

The problem is that the output doesn't take my customPARAM and it does something like MyEXE.exe -param1.


Solution

  • Instead of a whitespace separate arguments with ',':

    new ProcessBuilder("MyEXE.exe", "-param1 ", customPARAM, ...).start();
    

    See this: ProcessBuilder(String... command).