Why does the "where" command not work as expected for full paths?
Peruse these commands and the output:
where pg_ctl
C:\Program Files\PostgreSQL\12\bin\pg_ctl.exe
where pg_ctl.exe
C:\Program Files\PostgreSQL\12\bin\pg_ctl.exe
where "C:\Program Files\PostgreSQL\12\bin\pg_ctl.exe"
ERROR: Invalid pattern is specified in "path:pattern".
Why does the last one return an error instead of outputting itself/succeeding?
I have to be able to reliably enter either a "command" or a full path to an executable to this command to determine if it's an executable command or not.
Checking the error codes, I get this:
0
0
2
From where /?
:
NOTE: The tool returns an error level of 0 if the search is
successful, of 1 if the search is unsuccessful and
of 2 for failures or errors.
In other words, it doesn't return a proper 1 (search is unsuccessful) for the last command (the full path), but a 2 (failure or error). But even if it did return 1 as the exit code, that would still be wrong. It's supposed to return 0, because the path exists, so it is an executable command.
Where is a command for finding files. If you specify its full path, then what is the point of using where?
You can always use
if exist c:\path\filename.ext echo File does exist.
But if you really want to use the where command, then use it the way it was meant to be used. Use the /r parameter to specify the path, and put the command you are searching for as separate parameter.
Like so:
C:\>where /r "C:\Program Files\PostgreSQL\12\bin" pg_ctl.exe
C:\Program Files\PostgreSQL\12\bin\pg_ctl.exe
C:\>_