Setting environment varibale with output from a program

  • Thread starter Dennis.P.Mulqueeny
  • Start date
D

Dennis.P.Mulqueeny

I am trying to duplicate the following UNIX command in Windows XP DOS
mode:

set WFHM_DATE=`perl Calc_Prior_Work_Date.pl`

which would set the WFHM_DATE to the value of 20070703 (when run on
July 5th, 2007). I am running a third party software package that
supports a DOS mode which is the only place I can manipulate the
environment variables on-the-fly.

I have tried doing 'perl Calc_Prior_Work_Date.pl | set WFHM_DATE='.
It did not work.

Any ideas?

Dennis
 
P

Pegasus \(MVP\)

I am trying to duplicate the following UNIX command in Windows XP DOS
mode:

set WFHM_DATE=`perl Calc_Prior_Work_Date.pl`

which would set the WFHM_DATE to the value of 20070703 (when run on
July 5th, 2007). I am running a third party software package that
supports a DOS mode which is the only place I can manipulate the
environment variables on-the-fly.

I have tried doing 'perl Calc_Prior_Work_Date.pl | set WFHM_DATE='.
It did not work.

Any ideas?

Dennis

Every process you launch in Windows inherits its environmental
variables from its parent. If it modifies them then these changes
are not passed back to the parent.

To modify environmental variables globally you can use one of
these tools:
setx.exe (Win2000 Resource Kit)
setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)

Note that the change will affect all new processes but not
pre-existing ones.

By the way: "DOS" is an operating system, same as Unix. When
you say "DOS mode" you probably mean the Command Prompt.
 
D

Dennis.P.Mulqueeny

Every process you launch in Windows inherits its environmental
variables from its parent. If it modifies them then these changes
are not passed back to the parent.

To modify environmental variables globally you can use one of
these tools:
setx.exe (Win2000 Resource Kit)
setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)

Note that the change will affect all new processes but not
pre-existing ones.

By the way: "DOS" is an operating system, same as Unix. When
you say "DOS mode" you probably mean the Command Prompt.- Hide quoted text -

- Show quoted text -

Correct. I don't have setx available on my machine. I did find a
solution that is working for me in another thread. It boils down to
this:


for /f "tokens=*" %%a in ('perl perl/Calc_Prior_Work_Date.pl') do set
PRIOR_DATE=%%a

set yy=%PRIOR_DATE:~0,4%
set mm=%PRIOR_DATE:~4,2%
set dd=%PRIOR_DATE:~6,2%


The perl program is (all comments removed):
$| = 1;
use strict;
use diagnostics;
use Date::Manip;
main: {
Date_Init('TZ=US/Central', 'GlobalCnf=perl/Holidays.dates');
my $date = $ARGV[0] || 'today';
my $diff = Date_IsWorkDay($date);
$diff = 0 if (defined(Date_IsHoliday($date)));
print STDOUT &UnixDate(&Date_PrevWorkDay($date, $diff), '%Y%m%d');
exit 0;
}

The Holidays.dates file is:
*Holiday
1/1 = New Year's Day
Last Monday in May = Memorial Day
7/4 = Independence Day
First Monday in September = Labor Day
Fourth Thursday in November = Thanksgiving Day
12/25 = Christmas Day
 
D

Dennis.P.Mulqueeny

Every process you launch in Windows inherits its environmental
variables from its parent. If it modifies them then these changes
are not passed back to the parent.
To modify environmental variables globally you can use one of
these tools:
setx.exe (Win2000 Resource Kit)
setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)
Note that the change will affect all new processes but not
pre-existing ones.
By the way: "DOS" is an operating system, same as Unix. When
you say "DOS mode" you probably mean the Command Prompt.- Hide quoted text -
- Show quoted text -

Correct. I don't have setx available on my machine. I did find a
solution that is working for me in another thread. It boils down to
this:

for /f "tokens=*" %%a in ('perl perl/Calc_Prior_Work_Date.pl') do set
PRIOR_DATE=%%a

set yy=%PRIOR_DATE:~0,4%
set mm=%PRIOR_DATE:~4,2%
set dd=%PRIOR_DATE:~6,2%

The perl program is (all comments removed):
$| = 1;
use strict;
use diagnostics;
use Date::Manip;
main: {
Date_Init('TZ=US/Central', 'GlobalCnf=perl/Holidays.dates');
my $date = $ARGV[0] || 'today';
my $diff = Date_IsWorkDay($date);
$diff = 0 if (defined(Date_IsHoliday($date)));
print STDOUT &UnixDate(&Date_PrevWorkDay($date, $diff), '%Y%m%d');
exit 0;

}

The Holidays.dates file is:
*Holiday
1/1 = New Year's Day
Last Monday in May = Memorial Day
7/4 = Independence Day
First Monday in September = Labor Day
Fourth Thursday in November = Thanksgiving Day
12/25 = Christmas Day- Hide quoted text -

- Show quoted text -

I am so sorry, Pegasus. I forgot to thank you for your help.

Dennis
 
P

Pegasus \(MVP\)

I am trying to duplicate the following UNIX command in Windows XP DOS
mode:
set WFHM_DATE=`perl Calc_Prior_Work_Date.pl`
which would set the WFHM_DATE to the value of 20070703 (when run on
July 5th, 2007). I am running a third party software package that
supports a DOS mode which is the only place I can manipulate the
environment variables on-the-fly.
I have tried doing 'perl Calc_Prior_Work_Date.pl | set WFHM_DATE='.
It did not work.
Any ideas?

Every process you launch in Windows inherits its environmental
variables from its parent. If it modifies them then these changes
are not passed back to the parent.
To modify environmental variables globally you can use one of
these tools:
setx.exe (Win2000 Resource Kit)
setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)
Note that the change will affect all new processes but not
pre-existing ones.
By the way: "DOS" is an operating system, same as Unix. When
you say "DOS mode" you probably mean the Command Prompt.- Hide quoted
text -
- Show quoted text -

Correct. I don't have setx available on my machine. I did find a
solution that is working for me in another thread. It boils down to
this:

for /f "tokens=*" %%a in ('perl perl/Calc_Prior_Work_Date.pl') do set
PRIOR_DATE=%%a

set yy=%PRIOR_DATE:~0,4%
set mm=%PRIOR_DATE:~4,2%
set dd=%PRIOR_DATE:~6,2%

The perl program is (all comments removed):
$| = 1;
use strict;
use diagnostics;
use Date::Manip;
main: {
Date_Init('TZ=US/Central', 'GlobalCnf=perl/Holidays.dates');
my $date = $ARGV[0] || 'today';
my $diff = Date_IsWorkDay($date);
$diff = 0 if (defined(Date_IsHoliday($date)));
print STDOUT &UnixDate(&Date_PrevWorkDay($date, $diff), '%Y%m%d');
exit 0;

}

The Holidays.dates file is:
*Holiday
1/1 = New Year's Day
Last Monday in May = Memorial Day
7/4 = Independence Day
First Monday in September = Labor Day
Fourth Thursday in November = Thanksgiving Day
12/25 = Christmas Day- Hide quoted
text -

- Show quoted text -

I am so sorry, Pegasus. I forgot to thank you for your help.

Dennis

You're welcome. And as I said, setx.exe comes with the Windows
Resource Kit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top