# bach programming - running external bach files



## marksu (Oct 11, 2007)

I have 10 ready made bach files. 
For example bachfile1.bat ,bachfile2.bat, bachfile3.bat ... etc 

I would need a separate batch file that when it is run it runs batchfile1.bat.
Next time main batch file is run again, it would run batchfile2.bat etc.
When run 10 times, it would start again back from batchfile1.bat.

One problem is that the main bach file is allways run sameway so number paramethers can be sent to main bach file.

I do have programming experience but not mutch in batch programming.

Does any one have the knowledge how sutch batch file should be created?

marksu


----------



## marksu (Oct 11, 2007)

Never mind I found out it my self.
This runst bachfile1 to bachfile11 then next run number 12 it runs from start bachfile1 rtc...

@echo off

:: Works by comparing each digit

if [%E0%]==[] set E0=0

if %E0%==11 set E0=0
if %E0%==10 set E0=11
if %E0%==9 set E0=10
if %E0%==8 set E0=9
if %E0%==7 set E0=8
if %E0%==6 set E0=7
if %E0%==5 set E0=6
if %E0%==4 set E0=5
if %E0%==3 set E0=4
if %E0%==2 set E0=3
if %E0%==1 set E0=2
if %E0%==0 set E0=1

bachfile%E0%


----------



## marksu (Oct 11, 2007)

Hmm still some problems.
It works fine if using same memory space.
Meaning that keeping the dos prompt open and running the script time after time.

The problem is that my app that runs the script allways starts a new memoryspace so i loose the counter number as it is averytime reset to 0.

How can I save the number?

One possibility is to save the number to a file.
For example (I think?)
If exist counterValue.txt counterValue.txt
echo %E0% >> counterValue.txt

but how do i use that value in my external batch file.
meaning how do i read the number?


----------



## JohnWill (Oct 19, 2002)

Why not write a 10 line program to do the same thing? Personally, I'd probably use something like AutoIt to do this task, makes it simple.


----------



## marksu (Oct 11, 2007)

JohnWill said:


> Why not write a 10 line program to do the same thing? Personally, I'd probably use something like AutoIt to do this task, makes it simple.


I dloaded iniread and inimod from Internet that i found through google..
This should work but dont .
Some reason i cant get the value to E0 even though iniread looks like reading the inifile.

@echo off

:: reading ini file to get the counter value
iniread "counter.ini" "counter" "E0" "E0"

:: Works by comparing each digit

if %E0%==18 set E0=0
if %E0%==17 set E0=18
if %E0%==16 set E0=17
if %E0%==15 set E0=16
if %E0%==14 set E0=15
if %E0%==13 set E0=14
if %E0%==12 set E0=13
if %E0%==11 set E0=12
if %E0%==10 set E0=11
if %E0%==9 set E0=10
if %E0%==8 set E0=9
if %E0%==7 set E0=8
if %E0%==6 set E0=7
if %E0%==5 set E0=6
if %E0%==4 set E0=5
if %E0%==3 set E0=4
if %E0%==2 set E0=3
if %E0%==1 set E0=2
if %E0%==0 set E0=1

// this runs the external bach file
runBatch%E0%

:: write the new value to ini file
inimod counter.ini "counter" "E0" %E0%

Well maybe I have to take a look at Autoit. I just prefer not to start learn new script languges.


----------



## marksu (Oct 11, 2007)

Well the iniread.exe file dont seem to work on my XP OS so I replaced that line with:

:: get E0 value from ini file
setlocal enableextensions
for /f "tokens=2 delims==" %%? in (
'find /i "E0" ^< counter.ini') do set E0=%%?
if "%E0:~0,1%" equ " " set E0=%E0:~1%
echo E0= %E0%


Now it seems to work.


----------

