Computing.Net > Forums > Disk Operating System > Test Environment Variable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Test Environment Variable

Reply to Message Icon

Name: freediver211
Date: May 31, 2007 at 06:58:00 Pacific
OS: Windows XP
CPU/Ram: N/A
Product: N/A
Comment:

Before I attempt to use an environment variable in a DOS batch script I would like to test it to ensure it exist. How do you test an environment variable to ensure it was created?



Sponsored Link
Ads by Google

Response Number 1
Name: DosX
Date: May 31, 2007 at 08:04:46 Pacific
Reply:

Try this:

--------------------
@echo off
if "%var%"=="" then goto novar
echo Variable VAR does not exist
goto end
:novar
echo Variable VAR = %var%
:end
--------------------


0

Response Number 2
Name: freediver211
Date: May 31, 2007 at 09:28:10 Pacific
Reply:

Thanks for the post!

May I ask a follow up question?

How do I say:

if "%var%" NOT == "" (
:: do something here...
)

obvious the statement above isn't working...

thanks!


0

Response Number 3
Name: IVO
Date: May 31, 2007 at 09:48:23 Pacific
Reply:

If not "%var%"=="" Do something here...

By the way if you are coding to execute in a console window under XP, you can use more powerfull statements in your batch as in XP there is no DOS an what you see at prompt is actually an emulator, the NTVDM (NT Virtual DOS Machine).

So your previous test in XP is coded as

If not defined var ( Do something here...)

where the ( ) enable to code more than one statement.

Post in Programming Forum to get a lot of help from smart people.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Test Environment Variable

parse environment variable www.computing.net/answers/dos/parse-environment-variable/12203.html

trouble with environment variables www.computing.net/answers/dos/trouble-with-environment-variables/622.html

set versus @set? plus can environment variables be displayed www.computing.net/answers/dos/set-versus-set-plus-can-environment-variables-be-displayed/3510.html