Solved

DOS equivalent to Unix “export” command?

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 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