mardi 22 septembre 2020

Why does my batch file spontaneously stop executing?

I'm writing a batch file that does some work based on values it finds in a separate configuration file. Naturally, the first thing it does is verify that the configuration file exists. However, when executed, my batch file halts the instant it hits the if not exist ... line.

set CurrentFolder=%~dp0
set ParentFolder=%CurrentFolder%..\
set ConfigPath=%ParentFolder%parameters.cfg

notepad %ConfigPath%

if not exist "%ConfigPath%" (
    echo The required parameters.cfg file was not found. Aborting process.
    exit /B
)
echo Found parameters.cfg.

rem read config values & do stuff with them

For debugging, I added the notepad line to confirm that my path to the config file is valid, and sure enough when I run the batch script it opens the file in notepad and then the batch script stops as if it completed.

Aucun commentaire:

Enregistrer un commentaire