Having spaces in Runtime.getRuntime().exec with 2 executables

Each argument you pass to the command should be a separate String element.

So you command array should look more like…

String[] a = new String[] {
    "C:\path\that has\spaces\plink",
    "-arg1",
    "foo", 
    "-arg2",
    "bar",
    "path/on/remote/machine/iperf -arg3 hello -arg4 world"};

Each element will now appear as a individual element in the programs args variable

I would also, greatly, encourage you to use ProcessBuilder instead, as it is easier to configure and doesn’t require you to wrap some commands in "\"...\""

Leave a Comment