often discussed, but this seems a weired edge case.
In win cmd.exe I successfully run:
"c:Program Filesmyapp.exe" -my_arg="sth. with space"
and
"c:Program Filesmyapp.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 Filesmyapp.exe", "-my_arg=sth. with space"] // no extra quoting
["cmd.exe", "/c", ""c:Program Filesmyapp.exe"", "-my_arg=sth. with space"] // exe quoted
["cmd.exe", "/c", ""c:Program Filesmyapp.exe"", "-my_arg="sth. with space""] // exe & arg quoted
["cmd.exe", "/c", "c:Program Filesmyapp.exe", "-my_arg="sth. with space""] // arg quoted
// putting all as cmd.exe arg:
["cmd.exe", "/c", "c:Program Filesmyapp.exe -my_arg=sth. with space"] // no extra quoting
["cmd.exe", "/c", ""c:Program Filesmyapp.exe" -my_arg=sth. with space"] // exe quoted
["cmd.exe", "/c", ""c:Program Filesmyapp.exe" -my_arg="sth. with space""] // exe & arg quoted
["cmd.exe", "/c", "c:Program Filesmyapp.exe -my_arg="sth. with space""] // arg quoted
// calling *.exe directly
["c:Program Filesmyapp.exe", "-my_arg=sth. with space"] // no extra quoting
[""c:Program Filesmyapp.exe"", "-my_arg=sth. with space"] // exe quoted
[""c:Program Filesmyapp.exe"", "-my_arg="sth. with space""] // exe & arg quoted
["c:Program Filesmyapp.exe", "-my_arg="sth. with space""] // arg quoted
running this works fine:
["cmd.exe", "/c", "c:Program Filesmyapp.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?
question from:
https://stackoverflow.com/questions/66045955/java-processbuilder-in-windows-spaces-in-exe-path-and-in-argument 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…