问题
I am experiencing the following problem:
I would like to run ecd.exe from a command-line.
I have added its full path to the 'path' environment-variable.
When calling ecd.exe from command-line, I get the following output:
Error: ecd.exe should be located under the Eclipse home directory.
This executable runs correctly when I add its full path in the command-line.
I've figured that an identical file exists in some other path folder.
But I have not been able to find it anywhere within the file-system.
How can I find the path used by the command line when calling this executable?
回答1:
@ECHO OFF
SETLOCAL
SET "pathd=%cd%;%path%"
SET "pathd=%pathd:)=^)%"
FOR /f "delims=" %%a IN ('echo %pathd:;=^&ECHO %') DO IF EXIST "%%~a\j*.exe" ECHO %%~a
GOTO :EOF
This should find - well, J*.exe files on the path (since I don't have ecd.exe) - just substitute ecd.exe for j*.exe.
It appends the current path to the current directoryname separated by ; then changes each ) to ^) in the resulting string.
The for operates on the concatenated enhanced path-string by substituting for ; with &echo - the carets before the ) on the previous line and the & in this line "escapes" the character, cause cmd to disregard the special meaning and treat it as an ordinary character.
This provides %%a as each individual path directory in turn; see whether the file (j*.exe) exists in the directory, and echo the directoryname if the file is found.
来源:https://stackoverflow.com/questions/36624098/find-the-path-used-by-the-command-line-when-calling-an-executable