Click here to get back home

How to set environmental variables before running another command?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to set environmental variables before running another command? Meal 06-03-2008
Get Chitika Premium
Posted by Meal on June 3, 2008, 2:27 pm
Please log in for more thread options
Hi Perl expert,
I=92m writing a simple script for a building system on windows vista.
This script will run a .cmd file which sets a lot of environmental
variables. After this, the script need to run a build command.
The build command depends on these environmental variables.
If I run the .cmd file with system or exec and then run the build
command, the build command will not run within the correct
environment. The system or exec simply start a new process and set the
environmental variables there.
My current solution is as below.
exec(".\myenv.cmd&build -cC -amd64");
It works since there's an "&", but I doubt in the future I need to
add more complex commands. Absolutely I cannot concatenate each of
them with an '&'.
What's the correct solution for this issue?
Thanks.
Meal.

Posted by smallpond on June 3, 2008, 4:38 pm
Please log in for more thread options
Meal wrote:
> Hi Perl expert,
> I’m writing a simple script for a building system on windows vista.
> This script will run a .cmd file which sets a lot of environmental
> variables. After this, the script need to run a build command.
> The build command depends on these environmental variables.
> If I run the .cmd file with system or exec and then run the build
> command, the build command will not run within the correct
> environment. The system or exec simply start a new process and set the
> environmental variables there.
> My current solution is as below.
> exec(".\myenv.cmd&build -cC -amd64");
> It works since there's an "&", but I doubt in the future I need to
> add more complex commands. Absolutely I cannot concatenate each of
> them with an '&'.
> What's the correct solution for this issue?
> Thanks.
> Meal.


Why not set the environment variables within perl?

$ENV = 'C:\BDIR';

perldoc perlvar

The hash %ENV contains your current environment. Setting a value in "ENV"
changes the environment for any child processes you subsequently fork() off.

** Posted from http://www.teranews.com **

Posted by Jürgen Exner on June 3, 2008, 4:52 pm
Please log in for more thread options
> I’m writing a simple script for a building system on windows vista.
>This script will run a .cmd file which sets a lot of environmental
>variables. After this, the script need to run a build command.
> The build command depends on these environmental variables.

This has nothing to do with Perl but everything with how environment
settings are inherited between processes. And for obvious reasons
children are not allowed to change environment variables of their
parent (you Perl script) or even worse their siblings (the build
command).

Just set the env vars in the parent process (i.e. your Perl script) and
the child processes (build script) will inherit them.

jue

Posted by Meal on June 3, 2008, 4:56 pm
Please log in for more thread options
> > =A0I=92m writing a simple script for a building system on windows vista.=

> >This script will run a .cmd file which sets a lot of environmental
> >variables. After this, the script need to run a build command.
> > =A0The build command depends on these environmental variables.
>
> This has nothing to do with Perl but everything with how environment
> settings are inherited between processes. And for obvious reasons
> children are not allowed to change =A0environment variables of their
> parent (you Perl script) or even worse their siblings (the build
> command).
>
> Just set the env vars in the parent process (i.e. your Perl script) and
> the child processes (build script) will inherit them.
>
> jue

Thanks to both of you.
It seems there's no other way.
The .cmd file to set the variables is rather large, I definitely don't
want to set that much variables manually.

Posted by Jürgen Exner on June 3, 2008, 5:02 pm
Please log in for more thread options

>> Just set the env vars in the parent process (i.e. your Perl script) and
>> the child processes (build script) will inherit them.
>>
>> jue
>
>Thanks to both of you.
>It seems there's no other way.
>The .cmd file to set the variables is rather large, I definitely don't
>want to set that much variables manually.

Nobody is talking about setting them manually. Just set them in your
Perl script.

jue

Similar ThreadsPosted
Passing a command to a process that's already running September 19, 2005, 11:09 pm
running shell command without echo in terminal May 21, 2008, 3:50 pm
Trouble running a unix command with a subroutine call November 24, 2005, 7:03 am
problem running grep within system command in perl March 19, 2006, 12:53 pm
Environmental variable for CGI proxy May 16, 2006, 9:50 am
problem in setting environmental variable March 5, 2007, 4:59 am
Static variables for separate command-line calls? January 15, 2006, 11:22 am
How to construct new variables in a script from other variables and strings. May 12, 2006, 4:51 am
local variables and global variables June 27, 2006, 8:31 am
running ppm on XP 64 December 29, 2006, 2:04 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap