Find the path used by the command line when calling an executable

孤街醉人 提交于 2019-12-04 05:52:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!