Reputation: 435
I will try to explain my problem :
Per example :
The problem is :
When I launch master.bat, the current path is "D:\Master\" Then, when slave_01.bat is executed, it try to launch setup_01.exe from "D:\Master\" and not from "D:\Master\Slave\"
REM Master.bat
@ECHO OFF
TITLE Installing Applications
SET mypath=%~dp0
ECHO %mypath:~0,-1%
ECHO.
ECHO 1) Installing App 1
ECHO.
call D:\Master\Slave_01\slave_01.bat"
ECHO.
ECHO 2) Installing App 2
ECHO.
CALL D:\Master\Slave_02\slave_02.bat"
PAUSE
slave_0x files :
REM slave_01.bat
TITLE App 1
ECHO.
ECHO %mypath:~0,-1%
ECHO.
ECHO Installing App 1
ECHO Please wait...
START /wait setup_01.exe /SILENT /SP- /NORESTART
Is there a way to use the current directory from the slave_0x.bat file instead the current directory from the master.bat file in the slave_0x.bat to launch the setup_0x.exe file from the right directory ?
Regards
Upvotes: 3
Views: 3068
Reputation: 9266
To launch an executable that is in a different directory, add the relative path to the START
command. Use %~dp0
to get the path of the currently running batch file.
START /wait %~dp0\setup_01.exe /SILENT /SP- /NORESTART
This launches the executable, but it doesn't change the process current directory.
If your executable relies on the current directory, then you will need to cd
to that directory first. The easiest way to temporarily change directories is pushd
and popd
.
pushd %~dp0
START /wait setup_01.exe /SILENT /SP- /NORESTART
popd
Note: If the path or executable name can contain spaces, put the executable name in quotes as follows (including the mandatory dummy quotes)
START /wait "" "%~dp0\setup_01.exe" /SILENT /SP- /NORESTART
This is a common gotcha using the batch START
command. See How to create batch file in Windows using "start" with a path and command with spaces
Upvotes: 4