查找命令行在调用可执行文件时使用的路径 [英] Find the path used by the command line when calling an executable

查看:259
本文介绍了查找命令行在调用可执行文件时使用的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下问题:



我想运行 ecd.exe $ b>

我已将其完整路径添加到'path'环境变量。



当从命令行调用 ecd.exe 时,得到以下输出:

 错误:ecd.exe应位于Eclipse主目录下。 

当我在命令行中添加完整路径时,此可执行文件正确运行。






我发现在其他路径文件夹中存在相同的文件。 / p>

但我在文件系统中的任何位置都找不到它。



调用此可执行文件时,命令行使用的路径?

解决方案

  @ECHO OFF 
SETLOCAL
SETpathd =%cd%;%path%
SETpathd =%pathd:)= ^)%
FOR / f delims =%% a IN('echo%pathd:; = ^&ECHO%')DO IF EXIST%%〜a\j * .exeECHO %%〜a

GOTO:EOF

这应该会找到 - J * .exe 路径上的文件(因为我没有 ecd.exe ) - 只需替换 ecd.exe j * .exe



它将当前路径追加到当前目录名, c $ c>; ,然后在结果字符串中更改每个 ^)



用于连接的增强型路径字符串,通过替换; & echo - 之前的插入符号) $ c>& 在此行中转义字符,导致 cmd 忽略特殊含义并将其视为普通字符。 / p>

每个个人 path 目录提供 %% a 反过来;查看该目录中是否存在该文件( j * .exe ),如果找到该文件,则 echo


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?

解决方案

@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.

这篇关于查找命令行在调用可执行文件时使用的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆