Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The system cannot find the batch label specified

3,412 views
Skip to first unread message

Vizoere

unread,
Jan 23, 2009, 3:07:01 PM1/23/09
to
Hi all -- Hoping someone else has seen this particular issue.

"The system cannot find the batch label specified - RunReports"


I've written quite an extensive shell script that uses multiple "call :asdf"
type subroutine management. Everything works great until I get to a
particular section of the script. When calling the :RunReports label, I get
the above error.

I've done quite a bit of searching and have verified that my line endings
are [CR][LF] rather than just [LF]. I also tried adding 10 more blank lines
in front of the offending label just to make sure it was not crossing between
two 512 byte blocks.

I took everything out of the script except the call command and the label
itself and the error goes away so it seems that there are no weird hidden
characters on the line.

I wrote the entire script from scratch on a Windows XP SP2 machine using
Notepad2.exe from www.flos-freeware.ch. I copy it using Windows Explorer to
a shared network drive. Another admin copies it to her C: drive using
Windows Explorer, then copies it to a server inside of Terminal Services from
her C: drive, again using Windows Explorer. To eliminate at least some
problems that might possibly be caused by that program, I copied the entire
script into Windows Notepad and resaved. The problem persists.

As a workaround, I took the code in the particular section out and saved it
in its own .cmd file and changed the call command to, "call RunReports.cmd"
This is the way the script is currently running but it bothers me that I have
this problem.

I'm willing to post the script if it would be useful, though it is quite
long (420 lines). Part of it is pasted below.

Thanks for any thoughts you may have,
Jeremy C.


REM Step 7 - Kick off Report job.
call :Log SUBSTART STARTING :RunReports SUBROUTINE
call :RunReports
if errorlevel 1 (
call :Log SUBEND :RunReports SUBROUTINE FAILED with Error Level:
%ERRORLEVEL%
call :Log LOG ****************************
call :Log LOG * *
call :Log LOG * ***REPORT RUN FAILED*** *
call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (
call :Log SUBEND :RunReports SUBROUTINE FINISHED SUCCESSFULLY
)


:RunReports
call :Log LOG Running Trigger from: %TRIGGERDIR%
call :Log LOG trigger.bat %TRIGGERGATEWAY% %TRIGGERUSER% ***password***
%TRIGGERSECNS% %TRIGGERNAME%
cd /d %TRIGGERDIR%
trigger.bat %TRIGGERGATEWAY% %TRIGGERUSER% %TRIGGERPASS% %TRIGGERSECNS%
%TRIGGERNAME% | find /i "fired successfully"
set EL=ERRORLEVEL
cd /d %MYCD%
exit /b %EL%

Pegasus (MVP)

unread,
Jan 23, 2009, 3:25:34 PM1/23/09
to

"Vizoere" <Viz...@discussions.microsoft.com> wrote in message
news:6BF15932-5167-476A...@microsoft.com...

I was unable to reproduce the error you report, using the code fragment you
posted. I suggest you send the whole code, renamed as a .txt file, to this
address: pegasus_fnlATyahooDOTcom.

CRLF is the normal line terminator for batch files. However, under WinXP, LF
appears to work too. However, Unicode is bad news.


foxidrive

unread,
Jan 23, 2009, 3:34:33 PM1/23/09
to
On Fri, 23 Jan 2009 12:07:01 -0800, Vizoere
<Viz...@discussions.microsoft.com> wrote:

>"The system cannot find the batch label specified - RunReports"
>
>
>I've written quite an extensive shell script that uses multiple "call :asdf"
>type subroutine management. Everything works great until I get to a
>particular section of the script. When calling the :RunReports label, I get
>the above error.
>

>As a workaround, I took the code in the particular section out and saved it
>in its own .cmd file and changed the call command to, "call RunReports.cmd"
>This is the way the script is currently running but it bothers me that I have
>this problem.
>
>I'm willing to post the script if it would be useful, though it is quite
>long (420 lines). Part of it is pasted below.

I wonder if there is something recursive happening, or it has to do with
the length of labels, and at the same time, similar labels.

It'd help to see the script and see if it's reproducible elsewhere.

Vizoere

unread,
Jan 23, 2009, 3:43:01 PM1/23/09
to
Thanks Pegasus for your reply -- I'll send you the script shortly as a .txt
file.

I don't know that you'll be able to reproduce the problem with the script I
send but maybe you'll see something that I've done that causes the problem.

This script is not unicode nor has only [LF] as line ends. I mentioned that
because in my searching, that was the only problem people have reported that
causes this issue.

Much much thanks for anything you come up with.
Jeremy C.

"Pegasus (MVP)" wrote:

>
> "Vizoere" <Viz...@discussions.microsoft.com> wrote in message
> news:6BF15932-5167-476A...@microsoft.com...
> > Hi all -- Hoping someone else has seen this particular issue.
> >
> > "The system cannot find the batch label specified - RunReports"

[snip]

Vizoere

unread,
Jan 23, 2009, 4:05:01 PM1/23/09
to

"foxidrive" wrote:

Something recursive sounds like a possibility. I tested label length by
replacing the label with ":A" but no dice. Lastly, there are no other labels
similar to this one. I'll post the script in a separate note.

There are a few dependencies on other scripts as well but from what I can
tell, it's not related to them.

Thanks for the reply foxidrive,
Jeremy C.

PS. Leaving work for the weekend, be back Monday.

Vizoere

unread,
Jan 23, 2009, 4:07:02 PM1/23/09
to
@echo off

REM DProc.cmd
REM Written by Jeremy Carter
REM Daily Processing for BI Production
REM
REM 0.0.0 - 12/02/08 - Started work on script
REM 0.1.0 - 12/03/08 - Backup portion complete
REM 0.2.0 - 12/04/08 - Extract portion complete
REM 0.3.0 - 12/09/08 - Added Check for completed pull
REM Moved Prep variables to external .ini file
REM 0.4.0 - 01/20/08 - Added code to execute EP Macro
REM 0.5.0 - 01/20/08 - Added Summary subroutine
REM 1.0.0 - 01/21/08 - Added code to Trigger the report run schedule
set VERSION=1.0.0

setlocal ENABLEDELAYEDEXPANSION

REM Set Global variables and other miscellaneous preparation steps for the
script
call :Prep
echo.
echo.Log File: %DPROC_LOG%

goto :Skip1
REM Step 1 - Check services to make sure they are all running
call :Log SUBSTART STARTING :SERVICECHECK SUBROUTINE
call :ServiceCheck
if errorlevel 1 (
call :Log SUBEND :SERVICECHECK SUBROUTINE FAILED


call :Log LOG ****************************
call :Log LOG * *

call :Log LOG *!!!SERVICE CHECK FAILED!!!*


call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (

call :Log SUBEND :SERVICECHECK SUBROUTINE FINISHED SUCCESSFULLY
)
:Skip1
REM Step 2 - Wait for daily pull to complete
call :Log SUBSTART STARTING :CHECK4PULL SUBROUTINE
call :Check4Pull
if errorlevel 1 (
call :Log SUBEND :CHECK4PULL SUBROUTINE FAILED


call :Log LOG ****************************
call :Log LOG * *

call :Log LOG * !!!CHECK PULL FAILED!!! *


call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (

call :Log SUBEND :CHECK4PULL SUBROUTINE FINISHED SUCCESSFULLY
)

REM Step 3 - Move files from extract location to backup folder - 5 files
every day
call :Log SUBSTART STARTING :BACKUP SUBROUTINE
call :Backup
if errorlevel 1 (
call :Log SUBEND :BACKUP SUBROUTINE FINISHED WITH NON-FATAL ERRORS
) ELSE (
call :Log SUBEND :BACKUP SUBROUTINE FINISHED SUCCESSFULLY
)

REM Step 4 - Create new extract files
call :Log SUBSTART STARTING :EXTRACT SUBROUTINE
call :Extract
if errorlevel 1 (
call :Log SUBEND :EXTRACT SUBROUTINE FAILED


call :Log LOG ****************************
call :Log LOG * *

call :Log LOG * !!!EXTRACT FAILED!!! *


call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (

call :Log SUBEND :EXTRACT SUBROUTINE FINISHED SUCCESSFULLY
)

REM Step 5 - Kick off Macro in EP.
call :Log SUBSTART STARTING :EPMacro1 SUBROUTINE
call :EPMacro1
if errorlevel 1 (
call :Log SUBEND :EPMacro1 SUBROUTINE FAILED with Error Level: %ERRORLEVEL%


call :Log LOG ****************************
call :Log LOG * *

call :Log LOG * !!!MACRO FAILED!!! *


call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (

call :Log SUBEND :EPMacro1 SUBROUTINE FINISHED SUCCESSFULLY
)

REM Step 6 - Run ETL script
call :Log SUBSTART STARTING :RunETL SUBROUTINE
call :RunETL
if errorlevel 1 (
call :Log SUBEND :RunETL SUBROUTINE FAILED with Error Level: %ERRORLEVEL%


call :Log LOG ****************************
call :Log LOG * *

call :Log LOG * !!!ETL FAILED!!! *


call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (

call :Log SUBEND :RunETL SUBROUTINE FINISHED SUCCESSFULLY
)

REM Step 7 - Kick off Report job.
call :Log SUBSTART STARTING :RunReports SUBROUTINE
call :RunReports
if errorlevel 1 (
call :Log SUBEND :RunReports SUBROUTINE FAILED with Error Level:
%ERRORLEVEL%
call :Log LOG ****************************
call :Log LOG * *

call :Log LOG * !!!REPORT RUN FAILED!!! *


call :Log LOG * *
call :Log LOG * Review Log and perform *
call :Log LOG * corrective action *
call :Log LOG * *
call :Log LOG ****************************
goto :Summary
) ELSE (
call :Log SUBEND :RunReports SUBROUTINE FINISHED SUCCESSFULLY
)

REM Step 8 - Summary
call :Log SUBSTART STARTING :SUMMARY SUBROUTINE
set STATUS=COMPLETE
call :Summary
if errorlevel 1 (
call :Log SUBEND :SUMMARY SUBROUTINE FINISHED WITH NON-FATAL ERRORS
) ELSE (
call :Log SUBEND :SUMMARY SUBROUTINE FINISHED SUCCESSFULLY
)

goto :EOF

:Prep
cd /d "%~dp0"
set MYCD=%CD%
for /f "delims== tokens=1,* eol=;" %%A in (DProc.ini) do set %%A=%%B
if not exist "%CD%\LOG" md "%CD%\LOG"
if not exist "%EXTRACTLOC%" md "%EXTRACTLOC%"
call :Log INTRO
exit /b 0

:ServiceCheck
for /f "delims== tokens=1,* eol=;" %%A in (Services.txt) do (
if "%%A" == "SERVER" set SVR=%%B
if "%%A" == "SERVICE" (
sc \\!SVR! query "%%B" | find "RUNNING"
if ERRORLEVEL 1 (
call :Log LOG %%B Service not started on !SVR! -- Starting
sc \\!SVR! start "%%B" | find "START_PENDING"
if ERRORLEVEL 1 (
call :Log LOG Unable to start %%B service on !SVR!
exit /b 1
)
)
)
)
exit /b 0

:Check4Pull
call %PULLSCRIPT%
if "%ERRORLEVEL%" == "0" (
call :Log LOG Database reports "SUCCESS" for Daily Pull
exit /b 0
)
if "%ERRORLEVEL%" == "10" (
call :Log LOG CheckPull.ini file missing - Unable to check for pull
completion
exit /b 1
)
if "%ERRORLEVEL%" == "20" (
call :Log LOG Unable to create temporary script to check for pull completion
exit /b 1
)
if "%ERRORLEVEL%" == "30" (
call :Log LOG Unable to locate sqlplus.exe - Unable to check for pull
completion
exit /b 1
)
if "%ERRORLEVEL%" == "40" (
call :Log LOG sqlplus did not respond in a timely manner - Unable to check
for pull completion
exit /b 1
)
if "%ERRORLEVEL%" == "50" (
call :Log LOG sqlplus did not respond with a recognized Status in the run
window - Unable to check for pull completion
exit /b 1
)
if "%ERRORLEVEL%" == "100" (
call :Log LOG Database reports "FAIL" for Daily Pull
exit /b 1
)
call :Log LOG Unknown error code: %ERRORLEVEL% - Unable to check for pull
completion
exit /b 1

:Backup
call :Log LOG Extract Location: %EXTRACTLOC%
call :Log LOG Backup Location: %BACKUPLOC%
for /l %%A in (1,1,5) do if not exist "!FILE%%A!" set
BACKUPERROR=!BACKUPERROR!, !FILE%%A! doesn't exist
if "%BACKUPERROR%" == "" (
call :Log LOG All five extract files exist, moving to backup location
)
if not exist "%BACKUPLOC%" md "%BACKUPLOC%"
set BACKUPERROR=
for /l %%A in (1,1,5) do (
move "!FILE%%A!" "%BACKUPLOC%">nul2>nul
if not "!ERRORLEVEL!" == "0" set BACKUPERROR=!BACKUPERROR!, Unable to move
!FILE%%A!
)
if "!BACKUPERROR!" == "" (
call :Log LOG All five extract files moved successfully
exit /b 0
) ELSE (
call :Log LOG Errors in Backup Subroutine:
call :Log LOG %BACKUPERROR:~2%
exit /b 1
)

:Extract
REM Verify Script directory exists and is readable
cd /d %SQLSCRIPTS%
if /i not "%CD%" == "%SQLSCRIPTS%" (
call :Log LOG Unable to change directory to SQL Scripts directory:
call :Log LOG %SQLSCRIPTS%
exit /b 1
)
REM Create temporary sqlplus script to run extract script then quit
echo.@%EXTRACTSCRIPT%>DProc.sql
echo.quit>>DProc.sql
REM Verify needed files exist
if not exist "DProc.sql" (
call :Log LOG Unable to create temporary script in SQL Scripts directory:
call :Log LOG %SQLSCRIPTS%
exit /b 1
)
if not exist "%EXTRACTSCRIPT%" (
call :Log LOG Daily Processing Extract script does not exist:
call :Log LOG %SQLSCRIPTS%\%EXTRACTSCRIPT%
exit /b 1
)
call :Log LOG Daily Processing Extract script exists -- continuing
for /f %%A in ("sqlplus.exe") do (
if not exist "%%~f$PATH:A" (
call :Log LOG Unable to locate sqlplus.exe -- Not in current directory
or in path
exit /b 1
)
)
REM Run sqlplus
call :Log LOG sqlplus command line: sqlplus.exe %EXTRACTSWITCH%
%EXTRACTUSER%/***password***@%EXTRACTSERVER% @DProc.sql
start "SQL Plus -- Daily Extract" /min /D"%SQLSCRIPTS%" "%COMSPEC%" /c
sqlplus.exe %EXTRACTSWITCH% %EXTRACTUSER%/!EXTRACTPASS!@%EXTRACTSERVER%
@DProc.sql
REM Wait for sqlplus to complete
set WAITED=0
:Wait4SQLPlus1
if /i %WAITED% GEQ %MAXSPWAIT% (
call :Log LOG sqlplus command has taken longer than %MAXSPWAIT% seconds
to complete
exit /b 1
)
%MYCD%\sleep 10
set /a WAITED=%WAITED% + 10
tasklist | find /i "sqlplus.exe">nul2>nul && goto :Wait4SQLPlus1
call :Log LOG sqlplus command completed in less than %WAITED% seconds
REM Verify that the extract ran successfully
if errorlevel 1 (
call :Log LOG sqlplus exited with an unsuccessful error code: %ERRORLEVEL%
call :Log LOG Continuing with check of extract files
)
for /l %%A in (1,1,5) do if not exist "!FILE%%A!" set
EXTRACTERROR=!EXTRACTERROR!, !FILE%%A! doesn't exist
if not "%EXTRACTERROR%" == "" (
call :Log LOG One or more extract files missing:
call :Log LOG %EXTRACTERROR:~2%
exit /b 1
)
call :Log LOG All extract files exist
exit /b 0

:EPMacro1
REM Run Macro
"%MACRODIR%" /Macro=%MACRONAME1%
call :Log LOG Sent call to start Macro -- Waiting for it to complete
REM Wait for Macro to complete
set WAITED=0
:Wait4Macro1
if /i %WAITED% GEQ %MAXMACROWAIT% (
call :Log LOG Macro has taken longer than %MAXMACROWAIT% seconds to
complete
exit /b 1
)
%MYCD%\sleep 10
set /a WAITED=%WAITED% + 10
if not exist %MYCD%\Daily.Flag goto :Wait4Macro1
del %MYCD%\Daily.Flag
call :Log LOG Macro completed in less than %WAITED% seconds
exit /b 0

:RunETL
REM Verify Script directory exists and is readable
cd /d %SQLSCRIPTS%
if /i not "%CD%" == "%SQLSCRIPTS%" (
call :Log LOG Unable to change directory to SQL Scripts directory:
call :Log LOG %SQLSCRIPTS%
exit /b 1
)
REM Create temporary sqlplus script to run ETL script then quit
echo.@%ETLSCRIPT%>DProc.sql
echo.quit>>DProc.sql
REM Verify needed files exist
if not exist "DProc.sql" (
call :Log LOG Unable to create temporary script in SQL Scripts directory:
call :Log LOG %SQLSCRIPTS%
exit /b 1
)
if not exist "%ETLSCRIPT%" (
call :Log LOG Daily Processing ETL script does not exist:
call :Log LOG %SQLSCRIPTS%\%ETLSCRIPT%
exit /b 1
)
call :Log LOG Daily Processing ETL script exists -- continuing
for /f %%A in ("sqlplus.exe") do (
if not exist "%%~f$PATH:A" (
call :Log LOG Unable to locate sqlplus.exe -- Not in current directory
or in path
exit /b 1
)
)
REM Run sqlplus
call :Log LOG sqlplus command line: sqlplus.exe %ETLSWITCH%
%ETLUSER%/***password***@%ETLSERVER% @DProc.sql
start "SQL Plus -- Daily ETL" /min /D"%SQLSCRIPTS%" "%COMSPEC%" /c
sqlplus.exe %ETLSWITCH% %ETLUSER%/!ETLPASS!@%ETLSERVER% @DProc.sql
REM Wait for sqlplus to complete
set WAITED=0
:Wait4SQLPlus2
if /i %WAITED% GEQ %MAXSPWAIT% (
call :Log LOG sqlplus command has taken longer than %MAXSPWAIT% seconds
to complete
exit /b 1
)
%MYCD%\sleep 10
set /a WAITED=%WAITED% + 10
tasklist | find /i "sqlplus.exe">nul2>nul && goto :Wait4SQLPlus2
call :Log LOG sqlplus command completed in less than %WAITED% seconds
REM Verify that the ETL ran successfully
if errorlevel 1 (
call :Log LOG sqlplus exited with an unsuccessful error code: %ERRORLEVEL%
exit /b 1
)
exit /b 0

:RunReports
call :Log LOG Running Trigger from: %TRIGGERDIR%
call :Log LOG trigger.bat %TRIGGERGATEWAY% %TRIGGERUSER% ***password***
%TRIGGERSECNS% %TRIGGERNAME%
cd /d %TRIGGERDIR%
trigger.bat %TRIGGERGATEWAY% %TRIGGERUSER% %TRIGGERPASS% %TRIGGERSECNS%
%TRIGGERNAME%

if "%ERRORLEVEL%" == "1" (
cd /d %MYCD%
exit /b 0
)
cd /d %MYCD%
exit /b 1

:Summary
cd /d %MYCD%
echo.[Server]>email.cfg
echo.SMTPSERVER=%SMTPSERVER%>>email.cfg
echo.SMTPPORT=%SMTPPORT%>>email.cfg
echo.SMTPTIMEOUT=%SMTPTIMEOUT%>>email.cfg
echo.>>email.cfg
echo.[DProc]>>email.cfg
echo.FROM=%FROM%@%COMPUTERNAME%.%USERDNSDOMAIN%>>email.cfg
echo.TO=%TO%>>email.cfg
if "%STATUS%" == "COMPLETE" (
echo.SUBJECT=Daily Processes Completed>>email.cfg
echo.BODY1=Processing completed successfully.>>email.cfg
echo.BODY2=.>>email.cfg
echo.BODY3=Check attached log for details.>>email.cfg
) ELSE (
echo.SUBJECT=Daily Processes FAILED>>email.cfg
echo.BODY1=Processing exited without finishing>>email.cfg
echo.BODY2=.>>email.cfg
echo.BODY3=Review attached Log file and perform corrective action>>email.cfg
)
cscript email.vbs email.cfg DProc "%DPROC_LOG%"
exit /b %ERRORLEVEL%

:Log
if "%1" == "INTRO" (
echo.*********************>>"%DPROC_LOG%"
echo.* DProc.cmd *>>"%DPROC_LOG%"
echo.* v%VERSION% *>>"%DPROC_LOG%"
echo.*********************>>"%DPROC_LOG%"
echo.%D_YEAR%-%D_MONTH%-%D_DAY% - %T_HOUR%:%T_MINUTE%>>"%DPROC_LOG%"
)
if "%1" == "SUBSTART" (
set CMDLINE=%*
set CMDLINE=!CMDLINE:~9!
echo.>>"%DPROC_LOG%"
echo.!CMDLINE!>>"%DPROC_LOG%"
)
if "%1" == "SUBEND" (
set CMDLINE=%*
set CMDLINE=!CMDLINE:~7!
echo.!CMDLINE!>>"%DPROC_LOG%"
)
if "%1" == "LOG" (
set CMDLINE=%*
set CMDLINE=!CMDLINE:~4!
echo. !CMDLINE!>>"%DPROC_LOG%"
)
goto :EOF

billious

unread,
Jan 23, 2009, 4:39:42 PM1/23/09
to

"Vizoere" <Viz...@discussions.microsoft.com> wrote in message
news:6BF15932-5167-476A...@microsoft.com...
> Hi all -- Hoping someone else has seen this particular issue.
>
> "The system cannot find the batch label specified - RunReports"
>
>
[snip for brevity]
>

This certainly seems strange.

I've tried a simple batch using labels of length 8..14, with extra labels
being substrings of others and been unable to reproduce your problem, BUT
I'm using XPHSP3.

So, since the batch evidently works on YOUR machine, but appears not to work
on the final machine, is there an OS difference between these two?

I worry about a "System Administrator" who doesn't simply use a COPY - or
even a batch file to do the copying task. Involvement of PCG systems in the
process appears cumbersome.

Also, NOTEPAD is known to introduce problems by formatting the file. At a
stretch, there are subtle processing differences between .BAT and .CMD
files - although this seems to be irrelevant here - are you using .CMD or
.BAT? (I never use .CMD, so I'm no expert on the differences - I just know
they exist)

Could you get a copy of the ACTUAL batch that is being run, and compare it
to your original? Is the sysadmin changing something (like the password,
perhaps) and saving it without understanding that the format is being
altered?

Certainly an interesting problem - perhaps you'll be reduced to commenting
out the "@echo off" and getting the sysadmin to send you the
screen-report...not that easy for a PCG afficiando.

Or maybe you'll have to try deleting/adding sections of the code to see what
triggers the "can't find the label" problem.

(Meanwhile, on a sytlistic point, wby don't you move the ERROR part of your
LOG routine to a separate label, like

:ERRLOG
>>logfile echo\stars and stuff
:LOG
>>logfile echo\%*
goto :eof

then call ERRLOG or LOG depending on whether you want the error notice to
appear or not? Would sem to make the code-maintenance easier...

How about writing two EXTERNAL files, ERRLOG.BAT and LOG.BAT, set up
%logfilename% in each batch requiring logging, and call the appropriate
EXTERNAL file - that way, you don't have to have your logging routine in
each of your operational batchfiles?

ERRLOG.BAT could be

>>%logfile% echo\stars and stuff
CALL LOG %*

)


billious

unread,
Jan 23, 2009, 4:51:47 PM1/23/09
to

"Vizoere" <Viz...@discussions.microsoft.com> wrote in message
news:BDB98D5F-C81B-4D0B...@microsoft.com...
[snip]

>
> :RunReports
> call :Log LOG Running Trigger from: %TRIGGERDIR%
> call :Log LOG trigger.bat %TRIGGERGATEWAY% %TRIGGERUSER% ***password***
> %TRIGGERSECNS% %TRIGGERNAME%
> cd /d %TRIGGERDIR%
> trigger.bat %TRIGGERGATEWAY% %TRIGGERUSER% %TRIGGERPASS% %TRIGGERSECNS%

^^^ Missing "CALL" ? This will transfer to TRIGGER.BAT; what will happen
when TRIGGER.BAT ends? I believe it won't come back here...

> %TRIGGERNAME%
> if "%ERRORLEVEL%" == "1" (
> cd /d %MYCD%
> exit /b 0
> )
> cd /d %MYCD%
> exit /b 1
>

>[snip]


Al Dunbar

unread,
Jan 23, 2009, 6:04:50 PM1/23/09
to

"Vizoere" <Viz...@discussions.microsoft.com> wrote in message
news:6BF15932-5167-476A...@microsoft.com...

One problem is that this line:

set EL=ERRORLEVEL

will set the EL variable to the word "ERRORLEVEL", not to the value of the
ERRORLEVEL variable, which would require one of these two slightly different
commands:

set EL=%ERRORLEVEL%
set/a EL = ERRORLEVEL

If the script that you are running has gotten this bit right, then perhaps
there are other differences...

/Al


foxidrive

unread,
Jan 24, 2009, 8:36:48 AM1/24/09
to
On Fri, 23 Jan 2009 13:07:02 -0800, Vizoere
<Viz...@discussions.microsoft.com> wrote:

> %MYCD%\sleep 10
> set /a WAITED=%WAITED% + 10
> tasklist | find /i "sqlplus.exe">nul2>nul && goto :Wait4SQLPlus2
> call :Log LOG sqlplus command completed in less than %WAITED% seconds
> REM Verify that the ETL ran successfully
> if errorlevel 1 (

The code above is always going to exit with errorlevel 1 as find.exe will
return errorlevel 1 when sqlplus.exe is no longer running.

You can use the /wait switch with start and get the errorlevel when it's
done (but test if you are getting the errorlevel from sqlplus and not from
comspec).

REM Run sqlplus
call :Log LOG sqlplus command line: sqlplus.exe %ETLSWITCH%
%ETLUSER%/***password***@%ETLSERVER% @DProc.sql

start "SQL Plus -- Daily ETL" /W /min /D"%SQLSCRIPTS%" "%COMSPEC%" /c

Timo Salmi

unread,
Jan 24, 2009, 8:43:21 PM1/24/09
to
Al Dunbar <alan...@hotmail.com> wrote:
> will set the EL variable to the word "ERRORLEVEL", not to the value of the
> ERRORLEVEL variable, which would require one of these two slightly different
> commands:
>
> set EL=%ERRORLEVEL%
> set/a EL = ERRORLEVEL

The latter formulation appears to be false. At least in XP SP3 testing.
Even in that case we need

set /a el=%errorlevel%

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm

Al Dunbar

unread,
Jan 25, 2009, 12:40:49 AM1/25/09
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:%23FctP5o...@TK2MSFTNGP04.phx.gbl...

> Al Dunbar <alan...@hotmail.com> wrote:
>> will set the EL variable to the word "ERRORLEVEL", not to the value of
>> the ERRORLEVEL variable, which would require one of these two slightly
>> different commands:
>>
>> set EL=%ERRORLEVEL%
>> set/a EL = ERRORLEVEL
>
> The latter formulation appears to be false. At least in XP SP3 testing.
> Even in that case we need
>
> set /a el=%errorlevel%

oops, my bad. I was sure I tested that. I guess the difference is that since
ERRORLEVEL is not really an environment variable, the percent signs are
needed to expand its value, even on the right side of a set/a assignment.

/Al


Vizoere

unread,
Jan 26, 2009, 10:46:08 AM1/26/09
to
Excellent catch -- I wonder if that might be my problem. I'll test and
report back.

Thanks billious

Vizoere

unread,
Jan 26, 2009, 10:49:01 AM1/26/09
to
Wow, I didn't expect this much attention!
You are correct foxidrive, my errorcheck there will not perform as I had
intended and I'm quite embarrased that I didn't notice it myself.

Thanks!

Vizoere

unread,
Jan 26, 2009, 11:20:00 AM1/26/09
to
billious, I really appreciate the time you took to look through this and make
comments/suggestions!

"billious" wrote:

> So, since the batch evidently works on YOUR machine, but appears not to work
> on the final machine, is there an OS difference between these two?

I have not run it on my machine because many of the steps require files that
are only installed on the server. However, my machine is XP SP2 and the
server is W2K3 SP2

> I worry about a "System Administrator" who doesn't simply use a COPY - or
> even a batch file to do the copying task. Involvement of PCG systems in the
> process appears cumbersome.

Not sure what "PCG systems" is. Part of the complication of this process is
that I don't yet have admin rights to the server (I should be getting those
in the next month or so which will make troubleshooting easier).

> Also, NOTEPAD is known to introduce problems by formatting the file. At a
> stretch, there are subtle processing differences between .BAT and .CMD
> files - although this seems to be irrelevant here - are you using .CMD or

> ..BAT?

I've been using .cmd for my scripts for several years. I wasn't aware of
any differences in processing between .bat and .cmd, though I'll search for
that.

> Could you get a copy of the ACTUAL batch that is being run, and compare it
> to your original?

I did try this and did a 'fc' between the copy that was being run and my
local copy. No differences there. Also opened it back up in Notepad2 and
turned on the "Show Line Endings" option which shows [CR][LF] at the end of
every line.

> Certainly an interesting problem - perhaps you'll be reduced to commenting
> out the "@echo off" and getting the sysadmin to send you the
> screen-report...not that easy for a PCG afficiando.

A definite possibility. I'll keep that in mind if I don't get anywhere with
anything else.

> Or maybe you'll have to try deleting/adding sections of the code to see what
> triggers the "can't find the label" problem.

Done a little of that, but again, since I have to send the batch to another
admin and have them run it, I've tried not to be too intrusive by sending
script after script for them to run.

> (Meanwhile, on a sytlistic point, wby don't you move the ERROR part of your
> LOG routine to a separate label, like

The stars and such were a recent addition and I didn't give much thought to
them. I like your idea though. I'll do that. Thanks.

> How about writing two EXTERNAL files, ERRLOG.BAT and LOG.BAT, set up
> %logfilename% in each batch requiring logging, and call the appropriate
> EXTERNAL file - that way, you don't have to have your logging routine in
> each of your operational batchfiles?

As this is the only one of my scripts running on this server, my thought
process was to try to keep everything as consolidated as possible. I can
only guess that there will be more scripts to come. Shared logging scripts
is a great thought.


Again, thanks for the in-depth review :D

Vizoere

unread,
Jan 26, 2009, 11:31:01 AM1/26/09
to
You guys are right, another error checking problem. I ended up rewriting
that section anyway thinking that it was kind of kludgy.

Thanks!

"Al Dunbar" wrote:
> "Timo Salmi" wrote:

Pegasus (MVP)

unread,
Jan 26, 2009, 12:01:12 PM1/26/09
to

"Vizoere" <Viz...@discussions.microsoft.com> wrote in message
news:67657A3A-C753-413A...@microsoft.com...

> Thanks Pegasus for your reply -- I'll send you the script shortly as a
> .txt
> file.
>

Thanks for the file. I did analyse and run it but I was unable to reproduce
the effect you observe. Seeing that you have received so much feedback from
the best experts in the field, I didn't consider it necessary to duplicate
the work of others. However, as a general comment I suggest you review your
choice of language for your next project. In my opinion batch files are fine
when putting together a script spanning up to a few dozen lines at most.
After this a proper script language would be far superior. Here are a few
reasons:

- You can use debuggers to step through your program, see where it fails and
keep a tab on all variables. Debugging a batch file is horrible - which is
the main reason for your post!
- You can get scripts to alert you about undeclared variables (e.g. your
misspelt "errorlevel").
- It is much easier to write well-structured scripts than batch files.
- You can have local and global variables. (You mention "global" variables
but in fact all your variables are global!)
- You are not subject to the dreaded issue of "poison characters".
- Script files, if properly written, tend to run much faster than batch
files.


billious

unread,
Jan 26, 2009, 2:54:19 PM1/26/09
to

"Vizoere" <Viz...@discussions.microsoft.com> wrote in message
news:9EE16D5B-6570-47D1...@microsoft.com...

> billious, I really appreciate the time you took to look through this and
> make
> comments/suggestions!
>
>> I worry about a "System Administrator" who doesn't simply use a COPY - or
>> even a batch file to do the copying task. Involvement of PCG systems in
>> the
>> process appears cumbersome.
>
> Not sure what "PCG systems" is. Part of the complication of this process
> is
> that I don't yet have admin rights to the server (I should be getting
> those
> in the next month or so which will make troubleshooting easier).


The interface choice of today's self-declared "professional" - Point, Click
and Giggle.


>
>> Or maybe you'll have to try deleting/adding sections of the code to see
>> what
>> triggers the "can't find the label" problem.
>
> Done a little of that, but again, since I have to send the batch to
> another
> admin and have them run it, I've tried not to be too intrusive by sending
> script after script for them to run.
>

How about replacing steps you can't test directly with

echo x|find "x" >nul

for errorlevel 0 result

and

echo y|find "x" >nul

for errorlevel non-zero result?

That way, you can test your flow easily - just remember to replace the dummy
steps before releasing the batch...

Vizoere

unread,
Jan 27, 2009, 10:25:01 AM1/27/09
to
SUCCESS!!!

Adding the call in front of trigger.bat got rid of the error.

Odd behavior, but I'll take the win ;)

Thanks again billious!

0 new messages