Batch file 如何在windows BAT中获取程序完整路径?

Batch file 如何在windows BAT中获取程序完整路径?,batch-file,cmd,Batch File,Cmd,我可以使用%dp0获取当前bat文件路径 但是如何将python.exe转换为“C:\Python27\python.exe”?两种方法 call :label python.exe :label call %~dp$PATH:1 或者,如果您有可用的位置 for /f %f in ('where python.exe') do %f (此操作可能需要在批处理文件中使用双百分比[%%] 如果路径上有多个可执行文件,则需要类似于 set target= for /f %f in ('where

我可以使用%dp0获取当前bat文件路径

但是如何将python.exe转换为“C:\Python27\python.exe”?

两种方法

call :label python.exe
:label
call %~dp$PATH:1
或者,如果您有可用的
位置

for /f %f in ('where python.exe') do %f
(此操作可能需要在批处理文件中使用双百分比[%%]

如果路径上有多个可执行文件,则需要类似于

set target=
for /f %f in ('where python.exe') do (
    set target=%f
)
call %target%
测试蝙蝠

@for %%i in (python.exe) do @set py=%%~$PATH:i
@echo %py%

@for %%i in ( %py%) do @set py=%%~dpi
@echo py's directory is %py%
单线蝙蝠在哪里==

蝙蝠在哪里

@for %%i in (%*) do @if not "%%~$PATH:i"=="" (echo %%~$PATH:i) else echo %%i

where ls.exe where.bat python.exe
D:\Program Files\Git\usr\bin\ls.exe
E:\sourceCode\shell\where.bat
C:\Python27\python.exe

不,这是bat文件路径,我的意思是如何获取命令程序完整路径…作为stringPerhpas,您的意思是这样的==>where命令可能会帮助您。键入where/?在命令提示下。接下来,您可以使用for loopEh获取结果,您将其作为注释而不是答案发布。。。不确定我是否同时编辑了我的答案。@TylerY86确实具有良好的同步性;-)@elzooilogico看到我的单线蝙蝠了吗^_^