Solved

DOS equivalent to Unix “export” command?

Posted on 2004-05-01
3
10,064 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
  • 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 250 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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…
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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