Chek_env

PURPOSE   OPERATION   OPTIONS   COMMAND LINES   RELATED PROGRAMS


Author: Dan Mares, dmares @ maresware . com (you will be asked for e-mail address confirmation)
Portions Copyright 1998-2016 by Dan Mares and Mares and Company, LLC
Phone: 678-427-3275


Purpose

Chek_env is designed to check for the occurrence of an environment variable, and also to compare the value against a value input on the command line. Depending on the existence and value of the variable, the program returns an error level which can be checked for in a batch file.

This program is only useful when used in batch files to check the value of environment variables.


top

Operation

Chek_env is run from the command prompt, or in a batch file. It performs its check of the appropriate environment variable, and a value of the variable.

Depending on the existence and value of the variable, the program will return a DOS errorlevel of 0-4 which can then be compared and based on the value, additional action can be taken.


top

COMMAND LINES:

chek_env    VARIABLE
check_env VARIABLE VALUE

The errorlevels returned are:

ERRORLEVEL Meaning

0 VARIABLE is not in environment
1 VARIABLE is in environment
2 VARIABLE is in environment but not matching VALUE
3 VARIABLE is in environment and VALUE matches

Sample batch file:

chek_env  %1  %2
if errorlevel 3 goto three
if errorlevel 2 goto two
if errorlevel 1 goto one
if errorlevel 0 goto none

echo errorlevel %errorlevel%

:three
echo %1 is set, and has the value of %2
goto end

:two
echo %1 is set but DOES NOT have value of %2
goto end

:one
echo %1 is set but value not checked
goto end
:none 
echo %1 is NOT set
goto end
:end

NOTE: Don't forget, when checking values in a batch file, you must check for the highest value first.


top

Command Line

C:>CHEK_ENV    variable_to_check_for     value_of_the_variable_to_compare

C:>CHEK_ENV OS Windows_NT

top

Related Programs

None

top