On Fri, 2 May 2025 21:52:46 GMT, Oleksii Sylichenko <d...@openjdk.org> wrote:

>> A bit more investigation and some trial and error.
>> It appears that with `echo.`, cmd.com is searching for a file named "echo" 
>> and when it does not find it it reverts to the builtin.  But it has already 
>> wasted time searching the %Path% for a non-existent file.
>> A couple comments searching the internet suggested using either "/" or ":". 
>> Both are not part of file paths and are parsed differently.
>> In my trial and error on Windows 10, I consistently get an error from `cmd 
>> /c echo.`, 
>> `'echo.' is not recognized as an internal or external command...`
>> 
>> I'd propose to use `echo/` instead, the `/` will terminate the parsing of 
>> the command name and won't be interpreted as part of a file name and as an 
>> empty command option will be ignored.
>
> On the other hand, the test can be modified as follows: on Windows, pass an 
> empty string as an argument to `echo` and expect two double quotes followed 
> by a newline character as the valid result:
> 
> 
> String[] cmdp = Windows.is() ? new String[]{"cmd.exe", "/c", "echo", ""} : 
> new String[]{"echo"};
> String[] envp = {"Hello", "World"}; // Yuck!
> Process p = Runtime.getRuntime().exec(cmdp, envp);
> String expected = Windows.is() ? """\n" : "\n";
> equal(commandOutput(p), expected);
> 
> 
> What do you prefer: the "echo/" variant or the "double quotes" variant?

I'd use the 'echo/' version to keep the test simpler.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/23933#discussion_r2072193051

Reply via email to