variables question

  • Thread starter Thread starter Jay
  • Start date Start date
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
 
You only use two %% in For loops.

--
--------------------------------------------------------------------------------------------------
Goodbye Web Diary
http://margokingston.typepad.com/harry_version_2/2005/12/thank_you_and_g.html#comments
=================================================
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
 
Back
Top