Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I would appreciate if any one can help me on this. TIA.I am reading a logfile of a BATCH program that keeps track of my internal program that are executed that is After finishing Job1, it writes Job1 to logfile (It is a string). When the Job2 is done it writes "Job2" and so on. When an error occur I exit the program and when restarted it looks on the logfile for the last job that ran. Upto this point It is working fine. Now from here
I need to call the program that is after this. If I see job2, I need to call job3 and carry on. Can a string be added a numeric 1 or can this be done using labels?
HEre I am reading my logfile:
:restart
rem Read from input file and change the variable here:
echo e100 'set %%1='>%temp%.\tmp.bat
for %%? in (rcx 7 w q) do echo %%? >>%temp%.\tmp.bat
type %temp%.\tmp.bat|debug %temp%.\tmp.bat>nul
type %RESTARTFILE% >>%temp%.\tmp.bat
type %temp%.\tmp.bat | find "set %%1=" > %temp%.\tmp.bat
call %temp%.\tmp.bat RESTARTPARM
del %temp%.\tmp.bat
??
echo. RESTARTPARM=%RESTARTPARM% +1 //?
call %RESTARTPARM%
??
Thanks

Hi again, Aftab. Though I have helped you on your last subject, in which you needed to get the 'N'th line from a file into a variable, I still can't figure out what you're trying to do. Perhaps you should explain better...
Anyway, this is what I did understand: you've got a numeric value (N), and you want to get the 'N+1'th line from a file and save into a variable. For example, the numeric value is 2, than you want to get the third line from a file to a variable. Am I right?
In order to do this, use the following script. The log file is LOG.DAT, and the numric value is %N%. You should change those to your own values.
@echo off
set S= %=%
echo e100'SET %%1='> %temp%.\temp.bat
for %%? in (rcx 7 w q) do echo %%?>> %temp%.\temp.bat
type %temp%.\temp.bat |DEBUG %temp%.\temp.bat > nul
:: Below is 'LOG.DAT'
FC /n LOG.DAT nul > %temp%.\temp1.dat
FIND ":%S%%S%" < %temp%.\temp1.dat > %temp%.\temp2.dat
FIND/v "%S%%S%%S%%S%%S%1:%S%%S%" < %temp%.\temp2.dat > %temp%.\temp1.dat
FIND/n ":" < %temp%.\temp1.dat > %temp%.\temp2.dat
:: Below is '%N%'
FIND "[%N%]%S%%S%%S%%S%%S%" < %temp%.\temp2.dat >> %temp%.\temp.bat
set S=%=%
call %temp%.\temp.bat LINE
echo SET LINE=%%3> %temp%.\temp.bat
call %temp%.\temp.bat %LINE%
for %%? in (temp1.dat temp2.dat temp.bat) do del %temp%.\%%?
echo %LINE%WATCH OUT FOR LINE WRAPPING !
If %N%=4, %LINE% will be the 5th line from LOG.DAT. Is that what you wanted??
If I could understand the problem better, I whould probably be capable of making a simpler solution.
-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

I am sorry I have not explained well... I applogize first for that. I als owant to thank you for helping me and appreciate it. OK, First, the log file that I am reading got only 1 line.
So I don't need to read and find the n'th line. (Each time my main file calls a job and when the job finishes okay, it writes this logfile like job1).
So my log file after job4 is compleated, will contain : job4
Say an error occur on my main file and I exit the program (Note I am calling main file where my batch program is and from where I am reading the logfile)
Now by runing this program I go to the logfile and read the variable that is "job4"
So I know the last job that ran okay was job4.
Now (How to?) I need to execute a command like this:
Call Job5 (Note I am not runing Job4 rather runing next one)
from a list of commands:
Call Job1
Call Job2
Call Job3
Call Job4
Call Job5
Call Job6...Thus it should execute only job5 and Job6 (After Job4) .
Is this possible?

Opps Forgot to add some thing: I am doing this as a restart process so that the main program knows where it was left while calling a bunch of sub program (job1.bat...job6.bat). In case of an error it is going to exit and after the problem is fixed it is going to start from where it was left over. TIA
Is that enough info?
Can this be done?

Humm... Let's forget about logfiles and all that, let's talk about that main file itself... What you really want is a batch file that will read a list of commands and will execute one by one. If an error occurs, you would run the batch file again and it would restart from where the error occurred (skipping the command with error).
Is that it???
If YES, this would do it:
@echo off
if exist templist.dat goto restart
if not exist list.txt for %%? in (echo goto:eof) do %%? LIST.TXT not found.
copy LIST.TXT templist.dat > nul
:restart
echo e100'SET CMD='> %temp%.\pfx.dat
for %%? in (rcx 8 w q) do echo %%?>> %temp%.\pfx.dat
type %temp%.\pfx.dat |DEBUG %temp%.\pfx.dat > nul
:loop
copy %temp%.\pfx.dat %temp%.\temp.dat > nul
type templist.dat>> %temp%.\temp.dat
FIND "SET CMD=" < %temp%.\temp.dat > %temp%.\temp.bat
FIND/v "SET CMD=" < %temp%.\temp.dat > templist.dat
call %temp%.\temp.bat
if "%CMD%"=="" goto loopend
%CMD%
goto loop
:loopend
del templist.dat
for %%? in (temp.dat temp.bat pfx.dat) do del %temp%.\%%?
:eofWATCH OUT FOR LINE WRAPPING.
If this is not what you're looking for, and all that logfile thing is necessary, just say so (there are other solutions, though more complex).
-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

Secreet_Doom,
I First want to thank you so much... I ran this code and it does exactly what you just said. However I need this little different. Can you please help? Right now,>If an error occurs, you would run the batch file again and it would restart from where the error occurred (skipping the command with error).
But what I want, if an error occur, let it restart from the point of error, don't want to skip the error. Let's say, my list.txt says:
Call job1.bat
Call job2.bat
Call Job3.batAnd the error happens on Job2.
So rather restarting and executing that Job1 and job3 again, I want the program , after an error, just stop (after job2)(this gives a chance to fix the problem)and while a restart is done, can it just start on Job2 and finish job2 and job3....?Note: I don't need the logfile if this can be done without it. Again, you are really amazing and appreciate with all the help.
Thanks much.

Hi Aftab. You're welcome.
How will the error be detected?? I was assuming (I don't know why, this isn't very logic) that the error would freeze the computer (and would obviously crash the batch file), but perhaps it won't. How can the batch file 'know' the command had an error? ERRORLEVEL is changed? An error message is outputed to screen?
And when the batch is restarted, you want it to execute the command which had an error and the commands below it, right?
So, all I need to know is how to detect the error
-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

Hi,
THANKS Again. Yes, I was hoping to check the eror w error level some thing like"IF errorlevel 1 exit" since all my internal jobs will pass an error of success/failure..
>>And when the batch is restarted, you want it to execute the command which had an error and the commands below it, right?
Absolutely right. Do you think /suggest of any other approach on this entier thing....?

Hi Aftab! Here we go:
@echo off
echo e100'SET CMD='> %temp%.\pfx.dat
for %%? in (rcx 8 w q) do echo %%?>> %temp%.\pfx.dat
type %temp%.\pfx.dat |DEBUG %temp%.\pfx.dat > nul
if exist templist.dat goto continue
if not exist list.txt for %%? in (echo goto:eof) do %%? LIST.TXT not found.
copy LIST.TXT %temp%.\temp.dat > nul
:loop
copy %temp%.\pfx.dat %temp%.\temp.bat > nul
type %temp%.\temp.dat>> %temp%.\temp.bat
copy %temp%.\temp.bat templist.dat > nul
:continue
FIND "SET CMD=" < templist.dat > %temp%.\temp.bat
call %temp%.\temp.bat
if "%CMD%"=="" goto loopend
%CMD%
if errorlevel=1 goto error
FIND/v "SET CMD=" < templist.dat > %temp%.\temp.dat
goto loop
:error
echo Error detected - %CMD%
goto exit
:loopend
echo Command list ended.
del templist.dat
:exit
for %%? in (temp.dat temp.bat pfx.dat) do del %temp%.\%%?
:eofWATCH OUT FOR LINE WRAPPING !
I think this is what you want.
Please, let me know if it works and if that's what you wanted !
-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |