Leia argumentos da linha de comando (parâmetros) ou call /?
:
… If Command Extensions are enabled CALL changes as follows: … In addition, expansion of batch script argument references (%0, %1, etc.) have been changed as follows: … %~$PATH:1 - searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string …
The
FOR
command creates parameter variables which are identified with a letter rather than a number (e.g.%%G
). The Parameter Expansions described above can also be applied to these.
Aplicando acima ao seu caso (observe o percentual do dobro de suspiro em %%g
para usar em um script .bat
ou .cmd
):
for %%g in ("bin\myapp.exe") do @set "_pathToMyApp=%%~$PATH:g"
rem ↑↑ NO leading backslash
rem next line calls 'myapp.exe' using its fully qualified name
"%_pathToMyApp%"
Um exemplo real: (observe um único percentual de suspiro em %g
para usar no prompt de comando em uma janela cmd
aberta). Minha variável PATH
lê como …;C:\Utils\;…
sem referência adicional à pasta C:\Utils
( diretório base ), myapp.exe
é uma aplicação simples que exibe todos os parâmetros fornecidos:
d:\bat> myapp.exe
'myapp.exe' is not recognized as an internal or external command,
operable program or batch file.
d:\bat> bin\myapp.exe
The system cannot find the path specified.
d:\bat> set _
Environment variable _ not defined
d:\bat> for %g in ("bin\myapp.exe") do @set "_pathToMyApp=%~$PATH:g"
d:\bat> set _
_pathToMyApp=C:\Utils\bin\myapp.exe
d:\bat> "%_pathToMyApp%" display all parameters
param 0 = C:\Utils\bin\myapp.exe
param 1 = display
param 2 = all
param 3 = parameters
d:\bat>