setting variable

L

LWG

Can I set two variables with one line?

if %errorlevel% EQU 0 set loc=outiside and st=whs

when do we have to use EQU as compared to =?

Thx,
Larry
 
M

Matthias Tacke

LWG said:
Can I set two variables with one line?

if %errorlevel% EQU 0 set loc=outiside and st=whs
if %errorlevel% EQU 0 set loc=outiside && set st=whs
when do we have to use EQU as compared to =?
Have a look at if /? from the commandline. The Windowshelp is also
mostly underestimated. Start/Help/searchtab and good searchphrase
often lead to useful results. (When asked, you should extend the help
info. sorry I have a german version, don't know the exact question)

hth
Matthias
 
L

LWG

I was going to ask another question somewhat related. During our logon I
dump the output of ipconfig to a file on their c drive. I then scan it for
IP network to help make a decision. I have 4 ip networks to scan for and I
came up with the following mess: I would appreciate your suggestions...

findstr /i /l "10.29.12" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=hous
if %errorlevel% EQU 0 set st=whs

goto main

findstr /i /l "10.29.11" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=lou
if %errorlevel% EQU 0 set st=whs

goto main

findstr /i /l "10.29.10" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=pekin
if %errorlevel% EQU 0 set st=whs

goto main

findstr /i /l "10.29.14" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=edbq
if %errorlevel% EQU 0 set st=whs

also, this was before I implemented your suggestion...
 
M

Mark V

LWG wrote in
I was going to ask another question somewhat related. During our
logon I dump the output of ipconfig to a file on their c drive. I
then scan it for IP network to help make a decision. I have 4 ip
networks to scan for and I came up with the following mess: I
would appreciate your suggestions...

findstr /i /l "10.29.12" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=hous
if %errorlevel% EQU 0 set st=whs

goto main

findstr /i /l "10.29.11" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=lou
if %errorlevel% EQU 0 set st=whs

goto main

findstr /i /l "10.29.10" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=pekin
if %errorlevel% EQU 0 set st=whs

goto main

findstr /i /l "10.29.14" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=edbq
if %errorlevel% EQU 0 set st=whs

also, this was before I implemented your suggestion...

IF /?

ERRORLEVEL number Specifies a true condition if the last program
run returned an exit code equal to or greater than the number
specified.

IF %errorlevel% 0
no "=" or "EQU"
 
J

Jerold Schulman

Can I set two variables with one line?

if %errorlevel% EQU 0 set loc=outiside and st=whs

when do we have to use EQU as compared to =?

Thx,
Larry
yes.

if %errorlevel% EQU 0 set loc=outiside&set st=whs

EQU and == can be used interchangably.


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
B

Bill Stewart

Jerold Schulman said:
if %errorlevel% EQU 0 set loc=outiside&set st=whs

Hi Jerold,

Don't you mean:

if %ERRORLEVEL% EQU 0 (set LOC=outside & set ST=whs)

e.g. execute stuff in between ( ) only if the first condition is true?

Without ( ), doesn't the second 'set' command get executed unconditionally?

Thanks,

Bill
 
M

Matthias Tacke

LWG said:
I was going to ask another question somewhat related. During our logon
I dump the output of ipconfig to a file on their c drive. I then scan
it for IP network to help make a decision. I have 4 ip networks to scan
for and I came up with the following mess: I would appreciate your
suggestions...

findstr /i /l "10.29.12" %windir%\addr.dat

if %errorlevel% EQU 0 set loc=hous
if %errorlevel% EQU 0 set st=whs

goto main
snip

also, this was before I implemented your suggestion...
I don't understand what you are looking for?
A way to resolve these 4 tests a bit shorter?

st is always whs maybe this could be done before,

The options you use in the findstr are useless.
I think /i for ignore case and /l for exact match can both be omitted
since you look for numbers.
If you look for "10.29.1" and filter the output line with a for
statement for the occuring missing number it could be simplified.

hth
Matthias
 
M

Marty List

Mark V said:
IF /?

ERRORLEVEL number Specifies a true condition if the last program
run returned an exit code equal to or greater than the number
specified.

IF %errorlevel% 0
no "=" or "EQU"

No, that's incorrect. You can use the special variable ERRORLEVEL without
the percent signs and ==, but you can't mix both. Examples:

Invalid syntax: If %errorlevel% 0
Correct: If errorlevel 0
Seems to work, but not documented: If errorlevel==0
Invalid syntax: If errorlevel EQU 0
Correct: If %errorlevel% EQU 0


The most important thing to remember is that ERRORLEVEL (without the %
percents) is true if the value is equal to OR GREATER THAN the number you
are testing. %ERRORLEVEL% (with the % percents and one of the EQU; NEQ,
etc.) is true if the expression is exactly true.

Examples:

If ERRORLEVEL 2 Echo The errorlevel is equal to or greater than 2
If ERRORLEVEL 1 Echo The errorlevel is equal to or greater than 1
If ERRORLEVEL 0 Echo The errorlevel is equal to or greater than 0
If %ERRORLEVEL% EQU 2 Echo The errorlevel is exactly 2.
If %ERRORLEVEL% EQU 1 Echo The errorlevel is exactly 1.
If %ERRORLEVEL% EQU 0 Echo The errorlevel is exactly 0.
If %ERRORLEVEL%==0 Echo The errorlevel is exactly 0.
 
L

LWG

What I am trying to do is scan the ip address of the computer to basically
tell the batch file where the client is located so I can map another drive.
If it is one of the mentioned networks (10.29.11.0, 10.29.12.0, 10.29.13.0,
10.29.14.0) I want to do something different (just map another drive). That
is where all of this started (in my mind). I am an amatuer at this
(obviously) and want to make sense of each % and command. I am slow, and I
do appreciate your help...

Larry
 
M

Matthias Tacke

LWG said:
What I am trying to do is scan the ip address of the computer to
basically tell the batch file where the client is located so I can map
another drive. If it is one of the mentioned networks (10.29.11.0,
10.29.12.0, 10.29.13.0, 10.29.14.0) I want to do something different
(just map another drive). That is where all of this started (in my
mind). I am an amatuer at this (obviously) and want to make sense of
each % and command. I am slow, and I do appreciate your help...
Hmm, we'll try ,-)

==========sample output of german ipconfig =============
C:\>ipconfig

Windows 2000-IP-Konfiguration

Ethernetadapter "WLan":

Verbindungsspezifisches DNS-Suffix:
IP-Adresse. . . . . . . . . . . . : 192.168.3.246
Subnetzmaske. . . . . . . . . . . : 255.255.255.0
Standardgateway . . . . . . . . . : 192.168.3.254
==========sample output of german ipconfig =============

In my example I use IP-Adresse as findstring you have to
adapt it to the exact writing in your version.

=============GetIP.Cmd=======================
@echo off & setlocal enableextensions
for /F "tokens=2 delims=:" %%A in ('findstr "IP-Adresse" %windir%\addr.dat') DO set ipaddr=%%A
:: This line fills ipaddr with all text after the colon
:: in the above line IP-Adresse " 192.168.3.246"
:: To extract the relevant parts use statements like
:: the following offset(from 0), length
Echo Firstpart: %ipaddr:~1,3% gives 192
Echo Secndpart: %ipaddr:~5,3% gives 168
Echo Thirdpart: %ipaddr:~9,1% gives 3
Echo Lastpart : %ipaddr:~11,3% gives 246
=============================================
You should be able to adapt this example for your needs. Instead of
echoing you can build a new value for comparisons etc.

Help on the used commands whith
for /?
findstr /?
set /?

hth
Matthias
 
M

Mark V

Marty List wrote in
No, that's incorrect. You can use the special variable ERRORLEVEL
without the percent signs and ==, but you can't mix both.
Examples:

Invalid syntax: If %errorlevel% 0
Correct: If errorlevel 0
Seems to work, but not documented: If errorlevel==0
Invalid syntax: If errorlevel EQU 0
Correct: If %errorlevel% EQU 0


The most important thing to remember is that ERRORLEVEL (without
the % percents) is true if the value is equal to OR GREATER THAN
the number you are testing. %ERRORLEVEL% (with the % percents and
one of the EQU; NEQ, etc.) is true if the expression is exactly
true.

Examples:

If ERRORLEVEL 2 Echo The errorlevel is equal to or greater than 2
If ERRORLEVEL 1 Echo The errorlevel is equal to or greater than 1
If ERRORLEVEL 0 Echo The errorlevel is equal to or greater than 0
If %ERRORLEVEL% EQU 2 Echo The errorlevel is exactly 2.
If %ERRORLEVEL% EQU 1 Echo The errorlevel is exactly 1.
If %ERRORLEVEL% EQU 0 Echo The errorlevel is exactly 0.
If %ERRORLEVEL%==0 Echo The errorlevel is exactly 0.

Thanks for the correction. I don't know what I was thinking. ;-)
 
L

LWG

Matthias, this will definitely give me enough to get this done. Thank you
for your time, and I can only hope that if I keep working with this it will
sink in...

Appreciate it, Larry

Matthias Tacke said:
Hmm, we'll try ,-)

==========sample output of german ipconfig =============
C:\>ipconfig

Windows 2000-IP-Konfiguration

Ethernetadapter "WLan":

Verbindungsspezifisches DNS-Suffix:
IP-Adresse. . . . . . . . . . . . : 192.168.3.246
Subnetzmaske. . . . . . . . . . . : 255.255.255.0
Standardgateway . . . . . . . . . : 192.168.3.254
==========sample output of german ipconfig =============

In my example I use IP-Adresse as findstring you have to
adapt it to the exact writing in your version.

=============GetIP.Cmd=======================
@echo off & setlocal enableextensions
for /F "tokens=2 delims=:" %%A in ('findstr "IP-Adresse"
%windir%\addr.dat') DO set ipaddr=%%A
 
G

Guest

Use an & not the word AND. You also need another SET command.

IF %ERRORLEVEL% EQU 0 SET LOC=OUTSIDE & SET ST=WHS

Always use EQU. You never use = in it's place.

Austin M. Horst
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top