Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DOS equivalent to Unix “export” command?

Posted on 2004-05-01
3
Medium Priority
?
11,188 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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 a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

926 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