system command question

system command question

am 27.09.2011 22:43:50 von Amish Rughoonundon

Hi,
I am trying to run a make file from perl. For the make file to run,
some environment variables need to be set. Usually I would use a batch
file with the following setting
SET A_DIR=C:\TOOLS\TMS320
SET C_DIR=C:\TOOLS\TMS320
PATH=%PATH%;C:\TOOLS;C:\TOOLS\TMS320
make

and it works.

I tried to do this in perl using a system call but it failed
system("SET A_DIR=C:\\TOOLS\\TMS320 & SET C_DIR=C:\\TOOLS\\TMS320 &
PATH=\%PATH\%;C:\\TOOLS;C:\\TOOLS\\TMS320 & make >
compilation_output.txt");

Any idea why the system command is not setting the path and A_DIR and
C_DIR correctly.

Thanks,
Amish


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

RE: system command question

am 28.09.2011 13:02:44 von Ken Slater

> -----Original Message-----
> From: Amish Rughoonundon [mailto:amishrughoonundon@gmail.com]
> Sent: Tuesday, September 27, 2011 4:44 PM
> To: beginners@perl.org
> Subject: system command question
>
> Hi,
> I am trying to run a make file from perl. For the make file to run,
> some environment variables need to be set. Usually I would use a batch
> file with the following setting
> SET A_DIR=C:\TOOLS\TMS320
> SET C_DIR=C:\TOOLS\TMS320
> PATH=%PATH%;C:\TOOLS;C:\TOOLS\TMS320
> make
>
> and it works.
>
> I tried to do this in perl using a system call but it failed
> system("SET A_DIR=C:\\TOOLS\\TMS320 & SET C_DIR=C:\\TOOLS\\TMS320 &
> PATH=\%PATH\%;C:\\TOOLS;C:\\TOOLS\\TMS320 & make >
> compilation_output.txt");
>
> Any idea why the system command is not setting the path and A_DIR and
> C_DIR correctly.
>
> Thanks,
> Amish
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
The system call spawns a separate process, so the environment variables will
be set in the spawned process only.
Try setting these environment variables through the %ENV hash which contains
the current environment.
Ken



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/