Solved

DOS equivalent to Unix “export” command?

Posted on 2004-05-01
3
9,805 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

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…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now