Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Date as Environment Variable 2

Status
Not open for further replies.

pawanjit

Programmer
Jan 26, 2001
3
0
0
US
Hi All!!

I need to set Current system date as Environment Variable using a PERL or a BAT program. Some other BAT program needs to access this environment variable.

I have tried to do it using 3 different way in my PERL program (using some example instead of System date), but I am unable to set Environment variable value:

Here's what I have done:

use Win32::File;

# Method 1:
`SET dirDate=1234`;

# Method 2:
system "SET YYZ=1234";

# Method 3:
$ENV{'dirDate1'}='DB1';

############

After running above PERL Code, I go to DOS Prompt and enter SET to see the list of environment variables and their values. I dont see any of the above.

None of these environment variables get set. Can someone guide me to correct way?

Regards,

Pawan
email_pawan@yahoo.com
 
Pawan,

Setting the %ENV array, as you're doing above, will only affect programs that you run from within your Perl script. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I believe that in Windows, if you set an environment variable from within a console program via the SET command described above, the changes will only apply to programs that are launched from that instance of the command shell. In other words, it's not easy to set a globally-available environment variable.

You can test this by launching a command prompt, setting some environment variable to some value, then launching a second command prompt from the original shortcut and testing the value of that variable in the second window. You should be able to get two values for any given variable in two instances of the command prompt shell.

Windows NT (and, I assume, Windows 2000) lets you change global variables on the fly with the System properties, but Win9x (and, I assume, ME) only let you change global values for variables at boot time.

So, unless there is some API I'm missing, which is very possible, I believe you can only do what you propose to do by either chaining together your programs so they all launch from the same instance of your command prompt, or by making your setting persistent by writing it to some file somewhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top