Hello, I'm writing a batch script to copy some files, run a program (SARA) and read values from a file which SARA generates (chunklog.inf) - (and a bunch of other stuff not important here.)
However I'm having a major issue getting the values from chunklog.inf files to variables.
For example under where it says:
"rem fetch the current timecode from chunklog.inf" - I want to extract some text from chunklog.inf and place it in a file called timecode.txt - I then want to read the contents of timecode.txt into a variable and from that, pick the first 7 letters.Only problem is that I cannot get this part to work. timecode.txt holds the correct values but %_TIMECODE% and %TIMECODE% never gets assigned any values.
Something which is strange is that if I take out this bit of code and place it in its batch script and run that seperately (in a folder where chunklog.inf also exists) then it works perfectly...
Any of you have a clue of what's wrong?
The script:
----------------------------------
@echo offsetLocal EnableDelayedExpansion
set VERBOSE=NO
if [%1]==[-v] set VERBOSE=YES
d:
set LOGFILE=d:\dat\logfiles\evt\log\test.log
set LOGINNAME=xxx
set LOGINPASS=xxx
set PROCESSDIR=D:\DAT\logfiles\evt\process
set INCOMINGDIR=D:\DAT\logfiles\evt\incoming
set DEPOTDIR=D:\ibm\TCIM\depotcall :writelog "####################################"
call :writelog "Evt2Tcim initiated"
call :writelog "Checking for .evt files in D:\DAT\logfiles\evt\incoming"
if exist "%INCOMINGDIR%\*.evt" (
cd %INCOMINGDIR%
call :writelog "EVT file(s) found in %INCOMINGDIR%"for %%z in (*.evt) do (
call :cleanprocessing
copy %%z %PROCESSDIR%>nulcall :writelog "Processing %%z with SARA"
sara -lcdir %PROCESSDIR%call :writelog "Reading SARA output"
cd %PROCESSDIR%
rem //--
rem fetch the current timecode from chunklog.infFOR /F "tokens=16 delims= " %%M IN ('findstr /C:"((int) 0)" chunklog.inf') DO @echo %%~M > timecode.txt
SET /P _TIMECODE=<timecode.txt
SET TIMECODE=%_TIMECODE:~0,7%
if [%TIMECODE%]==[] (
call :writelog "A timecode could not be read from chunklog.inf"
GOTO :ERROR
)
call :writelog "Opened chunklog.inf and found the current timecode to be %TIMECODE%"rem --//
rem //--
rem fetch the current timestamp from chunklog.inf and calculate the new timecodeFOR /F "tokens=18 delims= " %%M IN ('findstr /C:"((int) 0)" chunklog.inf') DO @echo %%M > timestamp.txt
SET /P _TIMESTAMP=<timestamp.txt
SET TIMESTAMP=%_TIMESTAMP:~0,10%
if [%TIMESTAMP%]==[] (
call :writelog "A timestamp could not be read from chunklog.inf"
ยด GOTO :ERROR
)call :writelog "Opened chunklog.inf and found the end-timestamp to be %TIMESTAMP%"
call :writelog "Getting new timecode from command: chunkname %TIMESTAMP%"
chunkname %TIMESTAMP% > timestamp_base36.txt
FOR /F "tokens=1" %%N IN (timestamp_base36.txt) DO set NEWTIMECODE=%%~N
call :writelog "chunkname returned the code %NEWTIMECODE%"rem --//
rem //--
rem Replace the value in the chunklog.inf.tmpif exist chunklog.inf.tmp DEL chunklog.inf.tmp
call :writelog "replacing %TIMECODE% with %NEWTIMECODE% in chunklog.inf.tmp"for /f "tokens=* delims= " %%a in (chunklog.inf) do (
set str=%%a
set str=!str:%TIMECODE%=%NEWTIMECODE%!
echo !str! >> chunklog.inf.tmp
)
call :writelog "replaced existing chunklog.inf with chunklog. Backed up original chunklog.inf as chunklog.inf.old"
copy /Y chunklog.inf chunklog.inf.old>nul
copy /Y chunklog.inf.tmp chunklog.inf>nul
endlocal
rem --//rem //--
rem Rename the chunks
call :writelog "renaming the chunks: %PROCESSDIR%\chunks\%TIMECODE:~0,6%? %PROCESSDIR%\chunks\%NEWTIMECODE:~0,6%?"
rename %PROCESSDIR%\chunks\%TIMECODE:~0,6%? %PROCESSDIR%\chunks\%NEWTIMECODE:~0,6%?
rem --//
call :writelog "run bart.exe"
echo "bart.exe -restore -connect 5993 -gemdbdir %PROCESSDIR% -chunkdepot %DEPOTDIR% -login %LOGINname% -password %LOGINPASS%")
) else (
call :writelog "No EVT files to process"
)goto :end
:writelog
if %VERBOSE%==YES echo %1
echo %date% %time% %1 >> %LOGFILE%
GOTO :eof:cleanprocessing
rem -- Clean house
cd %PROCESSDIR%
call :writelog "Removing existing files from %PROCESSDIR%"
for %%f in (*.inf *.lsi *.evt *.props *.txt) do (
call :writelog "Deleting %%f"
del %%f>nul
)
IF EXIST %PROCESSDIR%\chunks (
call :writelog "Removing chunks from %PROCESSDIR%"
rd %PROCESSDIR%\chunks /s /Q
)
goto :eof
:ERROR
call :writelog "An error occurred. Program terminating."
GOTO :END
:END
--------------------------------------An example of chunklog.inf:
#dump of chunklog information generated by SARA
((int) 0) = (((string) "/LogPlatformInstances/Demonstration LogPlatforms/W86047"(string) "W86047:2009 12 26 22:12:39"(string) "Demo chunklog created by Sara"(string) "RA6AXK0"(time) 1260887993.000000(time) 1261887159.000000(string) "chunks"))
i think you need exclms here:
SET TIMECODE=!_TIMECODE:~0,7!if [!TIMECODE!]==[] (
call :writelog "A timecode could not be read from chunklog.inf"
GOTO :ERROR
)call :writelog "Opened chunklog.inf and found the current timecode to be !TIMECODE!"
and all similar references,. change %TIMECODE% to !TIMECODE!
see if that helps.
Thanks alot. That helped me fix the script.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |