Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DOS equivalent to Unix “export” command?

Posted on 2004-05-01
3
Medium Priority
?
10,951 Views
Last Modified: 2007-12-19
I am using Windows 2000’s Paleolithic batch programming language to set environment variables and pass them along to an executable (VB, MSAccess).

I am using this in a .BAT file:

Set MyVar=ThisIsWhatIWantToReadWithEnviron
Echo %MyVar%

So that sets the variable, but it’s only alive inside the batch file.

Then I need to fire up a program that does this in VB:

Dim MyVar as String
MyVar = Environ$(“ ThisIsWhatIWantToReadWithEnviron”)
MsgBox "Environ returned: " & MyVar

But the variable is empty.

Unix has a command “export” to push an environment variable out to other shells and executables.

Is there a DOS equivalent?

Thanks!
0
Comment
Question by:geekboysteves
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Droby10
ID: 10968609
"Unix has a command “export” to push an environment variable out to other shells and executables."

sort of.  export publishes an environment variable for inheritance by _child_ processes, and the same principal applies in windows.  however, windows environment variables are not segmented in this fashion, all are inherited, so the set command is all that is needed to accomplish both tasks.  any application started from within that dos/cmd batch script (or even the controlling shell in most cases), would inherit your desired environment.  it's just not a global environment where you can run the script and then double click the executable - because it would receive it's environment from explorer instead.

0
 
LVL 5

Accepted Solution

by:
Droby10 earned 750 total points
ID: 10968611
also...

----
Set MyVar=ThisIsWhatIWantToReadWithEnviron
----
MyVar = Environ$(“ ThisIsWhatIWantToReadWithEnviron”)
----

wouldn't the second line need to be:

MyVar = Environ$("MyVar")

0
 

Author Comment

by:geekboysteves
ID: 10968933
Whoops.  Of course you are right (see "also..." above) about my erroneous example code.  The reason it was not working for me was that in my batch file I had spaces on either side of the "=" in the Set command and that made the Set statement fail.  Once I removed the spaces (as shown here, but not in my actual code) my VB program regurgitated the values using Environ$() just fine.

Thanks for the speedy reply!
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I’ll show how research, determination, and use of modern technology helped me solve a DNA mystery.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question