As explained in #397 and here https://stackoverflow.com/a/356014/1907778cmd /c has problems with spaces in paths, which normally can be corrected in cmd / bat using double quotes. But if using some argument with cmd /c <argument>, the behavior is special for backwards compatibility if the first character is a double quote, in which case it will remove this first character as well as the last double quote in the argument, completely breaking the existing quotations.
Alternatives I have not taken:
You could use path segment wise quotation like C:\"my folder"\"my subfolder"\kotlinc.bat. This seemed to be a too invasive use.
Instead of using absolute paths, just set the ProcessBuilder's directory to kotlinc's parent dir, and call it with a relative path. Cleanest solution, but biggest change (and might split up the code pathways too much).
Directly call the kotlinc executable without cmd /c <path> indirection. Context under windows and pwd should still be fine on any NT version or newer.
Call powershell instead of cmd to trampoline commands. Probably more stable, but adds in additional tech and complexity for little gain.
Instead, this PR just prefixes the quoted path with a space character, disabling this special cmd mode. The now also quoted path is read in correctly, even if it contains spaces. A prefixed space outside quotation marks is effectively ignored even in cmd's command mode. Because this workaround is only needed on Windows while using cmd, it's using an if.
Because there would now be 5 identical when expressions in the class to determine which quotes to use, as well as two different string concatenations, both have been simplified into a simple val and template interpolation on all 5 instances.
I might oversee some edge case, so any pointers would be more than welcome.
As explained in #397 and here https://stackoverflow.com/a/356014/1907778
cmd /c
has problems with spaces in paths, which normally can be corrected in cmd / bat using double quotes. But if using some argument withcmd /c <argument>
, the behavior is special for backwards compatibility if the first character is a double quote, in which case it will remove this first character as well as the last double quote in the argument, completely breaking the existing quotations.Alternatives I have not taken:
C:\"my folder"\"my subfolder"\kotlinc.bat
. This seemed to be a too invasive use.directory
to kotlinc's parent dir, and call it with a relative path. Cleanest solution, but biggest change (and might split up the code pathways too much).cmd /c <path>
indirection. Context under windows and pwd should still be fine on any NT version or newer.Instead, this PR just prefixes the quoted path with a space character, disabling this special cmd mode. The now also quoted path is read in correctly, even if it contains spaces. A prefixed space outside quotation marks is effectively ignored even in cmd's command mode. Because this workaround is only needed on Windows while using cmd, it's using an if.
Because there would now be 5 identical
when
expressions in the class to determine which quotes to use, as well as two different string concatenations, both have been simplified into a simpleval
and template interpolation on all 5 instances.I might oversee some edge case, so any pointers would be more than welcome.