Kalamalka Kid
Kalamalka Kid

Reputation: 180

call command for bat script not working

Essentially I have two .bat scripts that work just fine individually, however I wanted to combine the two scripts into one action as i have it assigned to a hotkey and want all of this with one press of a key, not two but am having problems because the scripts are in different directories.

Below are my two scripts:

BLAH-Script.bat

RE4_UHD_BLAH_Tool.exe -p
DEL /F /S /Q /A "F:\r101\r101_09.AEV"

and the second script:

UDAS_TOOL.bat:

DEL /F /S /Q /A "F:\st1\rl01.udas"
ping -n 1 localhost
DEL /F /S /Q /A "F:\UDAS Tool\r101.udas"
UDAS_Tool.exe -p

Now, both of these work great on their own because each of the scripts calls on an .exe that is in the same DIR as the script that calls them, but trying to get them into one .bat file has not worked using the CALL function because one of the scripts exists in an outside directory.

I have tried to make a new .bat script that would execute both bat scripts in one:

call "F:\pack\BLAH-Script.bat"
ping -n 1 localhost
call "F:\pack\UDAS\UDAS_TOOL.bat"

However this does not work.The files are not packaged by the exe tools as intended.

To try and figure out the problem I added pause command between scripts:

call "F:\pack\BLAH-Script.bat"
pause
call "F:\pack\UDAS_TOOL.bat"

This command allowed me to read the output before the window was closed and yielded the culprit. In the first script I am getting the following error:

F:\UD - r101-->RE4_UHD_BLAH_Tool.exe -p 'RE4_UHD_BLAH_Tool.exe' is not recognized as an internal or external command, operable program or batch file.

I believe what is happening it that each file works fine if run in its own directory because they are in the same DIR as the .exe they are calling, but the first .bat file will not execute because the third bat file ( the one that is that is calling the first & second) is not in the same DIR as the first.

I have tried:

CD /D "F:\pack"   
call "F:\pack\BLAH-Script.bat"
pause
CD /D "F:\pack"
call "F:\pack\UDAS\UDAS_TOOL.bat"

with the same error. How do I get the directories sorted out ?

Upvotes: 0

Views: 8265

Answers (1)

Magoo
Magoo

Reputation: 79982

In theory, you could simply fully-qualify the executable path, or make sure that the executables are located on the path.

However, some programs assume that the executable is in the current directory, and expect that configuration files, etc. are similarly in that directory, so what I'd do is

in each batch, after the initialisation ceremony (@echo off/setlocal...) add a

pushd "actualexcutablelocation"

and ensure that on exit from the batch,

popd

is executed to restore to the original directory.

pushd switches current directory to the nominated directory until a popd is executed to return to the original.

Upvotes: 1

Related Questions