Run external program with custom argumets

59 Views Asked by At

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.

1

There are 1 best solutions below

0
Shiro On BEST ANSWER

Instead of a whitespace separate arguments with ',':

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

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