I have an application and executables. I want my application to run my executables.
The executable files are in a folder, lets say in “c:\sample”.
In this directory there is a batch file that calls my exe’s. like:
start a1.exe
start a2.exe
start a3.exe
let’s name it as startAll.bat
and suppose every exe has a data like a1.dat a2.dat … and these data files are near this exe’s.
I want to call this batch file by my application.
system("c:\\\\sample\\\\startAll.bat");
when I call it like that, command cannot find these exe’s.
if I add directory names to batch files, it can not find the data that time.
I think it is because of working directory.
start c:\sample\a3.exe
how can I change the working directory before I call this batch file?
or do you suggest anything else?
Call
chdir("C:\\sample")before callingsystem(...)Or put a
cdcommand in your batch fileEDIT
Since you’re not on C: the first lines of the batch script should be
EDIT2
Using the suggestions made by Johannes and MattH a much better version of the BAT file would start with something like this
Now the bat file will work regardless of the directory it’s in as there are no hard coded paths. SETLOCAL is used to avoid side effects from running the script (like changing directory or setting environment variables)