On Fri, 2 May 2025 21:08:46 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> That sounds brittle. The "echo." usage is not specified, only shown as an 
>> example.
>> Under what command parsing rule does it run exactly the "echo" builtin?
>
> 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?

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

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

Reply via email to