--- @echo off cd /d %~dp0 set testExe="D:\a bc\test.exe" FOR /F "tokens=1 delims=" %%I IN (%testExe%) DO ( IF "%%~nxI"=="test.exe" ( pushd "%%~dpI" FOR /F "tokens=3" %%M IN ('.\%%~nxI --help ^| findstr "TargetStr"') DO ( set kekka=%%M ) popd ) ) @echo %kekka% pause ---