often discussed, but this seems a weired edge case.
In win cmd.exe I successfully run:
"c:\Program Files\myapp.exe" -my_arg="sth. with space"
and
"c:\Program Files\myapp.exe" -my_arg="sth_without_space"
in java ProcessBuilder.command(xxx) following fails with "c:\Program" was not a valid command (xxx contains following array):
// using cmd.exe:
["cmd.exe", "/c", "c:\Program Files\myapp.exe", "-my_arg=sth. with space"] // no extra quoting
["cmd.exe", "/c", "\"c:\Program Files\myapp.exe\"", "-my_arg=sth. with space"] // exe quoted
["cmd.exe", "/c", "\"c:\Program Files\myapp.exe\"", "-my_arg=\"sth. with space\""] // exe & arg quoted
["cmd.exe", "/c", "c:\Program Files\myapp.exe", "-my_arg=\"sth. with space\""] // arg quoted
// putting all as cmd.exe arg:
["cmd.exe", "/c", "c:\Program Files\myapp.exe -my_arg=sth. with space"] // no extra quoting
["cmd.exe", "/c", "\"c:\Program Files\myapp.exe\" -my_arg=sth. with space"] // exe quoted
["cmd.exe", "/c", "\"c:\Program Files\myapp.exe\" -my_arg=\"sth. with space\""] // exe & arg quoted
["cmd.exe", "/c", "c:\Program Files\myapp.exe -my_arg=\"sth. with space\""] // arg quoted
// calling *.exe directly
["c:\Program Files\myapp.exe", "-my_arg=sth. with space"] // no extra quoting
["\"c:\Program Files\myapp.exe\"", "-my_arg=sth. with space"] // exe quoted
["\"c:\Program Files\myapp.exe\"", "-my_arg=\"sth. with space\""] // exe & arg quoted
["c:\Program Files\myapp.exe", "-my_arg=\"sth. with space\""] // arg quoted
running this works fine:
["cmd.exe", "/c", "c:\Program Files\myapp.exe", "-my_arg=sth_without_space"]
The issues seem to start when the *.exe path and the arg contain whitespaces.
[edit]: My question is: How can you run it with whitespaces in the exe's path AND in the arg's content?