You can use my universal script for executing a command in a specified working directory:
CALL :EXEC_IN e:\bar run1.bat
The EXEC_IN batch-function is:
@ECHO OFF :: Execute a program inside a specified working directory :: 1. Working directory :: 2. Full file name :: 3+ Arguments :EXEC_IN SETLOCAL :: Scan fixed positional arguments: SET WD=%1&SHIFT SET FL=%1&SHIFT :: Collect all arguments into %ALL%: :EI_AA_START IF [%1]==[] GOTO EI_AA_END SET ALL=%ALL%%SEP%%1 SET SEP= SHIFT GOTO :EI_AA_START :EI_AA_END :: Execute command %FL% in directory %WD% with args %ALL%: PUSHD %WD% CALL %FL% %ALL% POPD ENDLOCAL EXIT /B
If desired, feel free to modify it to take the working directory from the file path intead of passing it as the first argument:
CALL :EXEC_IN_F e:\bar\run1.bat
This modified script is:
:: Execute a program with its location as working directory: :: 1. Full path to the executable :: 2+ Arguments :EXEC_IN_F SETLOCAL :: Scan fixed positional arguments: SET FL=%1 SET WD=%~p1 SHIFT :: Collect all arguments into %ALL%: :EI_AA_START IF [%1]==[] GOTO EI_AA_END SET ALL=%ALL%%SEP%%1 SET SEP= SHIFT GOTO :EI_AA_START :EI_AA_END :: Execute command %FL% in directory %WD% with args %ALL%: PUSHD %WD% CALL %FL% %ALL% POPD ENDLOCAL EXIT /B