Consider the following batch file test.bat
:
CD C:\SOFTWARE
program.exe
This script is run from C:\ELSWHERE
C:\ELSWHERE> C:\test.bat
After the script exits the current working directory is now C:\SOFTWARE
and not the previous working directory C:\ELSWHERE
.
The script changes the working directory to C:\SOFTWARE
because program.exe
requires config.ini
which is located in C:\SOFTWARE
and locates it using the current working directory. If the software program.exe
were to be run directly from, say, C:\
or C:\ELSWHERE
using its absolute path name, the program will be unable to read its config and throw an error. The solution to this is to CD
to the C:\SOFTWARE
folder first and run the program from there.
The problem with doing this in a batch file is that this also changes the working directory of the previous environment, be it the host COMMAND.COM working directory or another batch file.
This is not a problem from an NT-based command prompt which has access to pushd
and popd
, along with other useful environment variables to preserve the old working directory. But is it possible to do this within the constraints of the old MS-DOS\Win9x command.com?
cmd /c script.bat
. In such an old system CMD might becommand.com
or whatever.command.com
. Thecmd.exe
interpreter is from Windows NT. And surlrisingly, usingcommand.com /c script.bat
clobbers the working directory of the parent interpreter. I would have expected this to work as well.