J
Jay
I've created a batch file to query a text file and make decisions based on the text file's content. The text file looks like this:
-------------------file is below------------------------------------------------------------------------------------------
-----------
0
-------------------file is above------------------------------------------------------------------------------------------
It's a 3-line file called abc.out, first line blanks, second line dashes, third line 0 preceded by blanks.
This is the content of abc.bat:
-------------------file is below------------------------------------------------------------------------------------------
for /F "skip=2 tokens=1" %%a in (abc.out) do (set abc=%%a)
echo %%abc%%
if %%abc%% == 0 goto none
if %%abc%% NEQ 0 goto some
goto error
:none
echo There are no users of ${dbase}.
goto exit
:some
echo **JOB FAILURE**. %%abc%% logins are accessing the database
goto exit
:error
echo Unknown error caused failure
goto exit
:exit
-------------------file is above------------------------------------------------------------------------------------------
The job doesn't work as expected, in that the contents of variable abc are lost immediately, so this is the output I get:
-------------------file is below------------------------------------------------------------------------------------------
C:\WINDOWS\Temp>for /F "skip=2 tokens=1" %a in (abc.out) do (set abc=%a )
C:\WINDOWS\Temp>(set abc=0 )
C:\WINDOWS\Temp>echo %abc%
%abc%
C:\WINDOWS\Temp>if %abc% == 0 goto none
C:\WINDOWS\Temp>if %abc% NEQ 0 goto some
C:\WINDOWS\Temp>echo **JOB FAILURE**. %abc% logins are accessing the database
**JOB FAILURE**. %abc% logins are accessing the database
C:\WINDOWS\Temp>goto exit
-------------------file is above------------------------------------------------------------------------------------------
Can anybody tell me why my code doesn't work, and how I can get it to work properly?
Jay
-------------------file is below------------------------------------------------------------------------------------------
-----------
0
-------------------file is above------------------------------------------------------------------------------------------
It's a 3-line file called abc.out, first line blanks, second line dashes, third line 0 preceded by blanks.
This is the content of abc.bat:
-------------------file is below------------------------------------------------------------------------------------------
for /F "skip=2 tokens=1" %%a in (abc.out) do (set abc=%%a)
echo %%abc%%
if %%abc%% == 0 goto none
if %%abc%% NEQ 0 goto some
goto error
:none
echo There are no users of ${dbase}.
goto exit
:some
echo **JOB FAILURE**. %%abc%% logins are accessing the database
goto exit
:error
echo Unknown error caused failure
goto exit
:exit
-------------------file is above------------------------------------------------------------------------------------------
The job doesn't work as expected, in that the contents of variable abc are lost immediately, so this is the output I get:
-------------------file is below------------------------------------------------------------------------------------------
C:\WINDOWS\Temp>for /F "skip=2 tokens=1" %a in (abc.out) do (set abc=%a )
C:\WINDOWS\Temp>(set abc=0 )
C:\WINDOWS\Temp>echo %abc%
%abc%
C:\WINDOWS\Temp>if %abc% == 0 goto none
C:\WINDOWS\Temp>if %abc% NEQ 0 goto some
C:\WINDOWS\Temp>echo **JOB FAILURE**. %abc% logins are accessing the database
**JOB FAILURE**. %abc% logins are accessing the database
C:\WINDOWS\Temp>goto exit
-------------------file is above------------------------------------------------------------------------------------------
Can anybody tell me why my code doesn't work, and how I can get it to work properly?
Jay