CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Executing 'set' Windows commend from Perl

 



zatlas1
Novice

Jun 24, 2011, 11:06 AM

Post #1 of 8 (2410 views)
Executing 'set' Windows commend from Perl Can't Post

Hi All

I need to set some local environment variables dynamically for a batch that I run (.cmd file, WinXP.)

I tried to issue a little Perl script from within the batch. To simplify, this is all:


Code
my $rc=system ("set ABC=value");  

print "$rc\n";





I get return code of 0, indicating that all went well.

back to the next command in the batch, I issue

set ABC

and get: 'Environment variable ABC not defined'

if I do this in the batch itself, I have no problem:


Code
set ABC=value  

set ABC



Is there a way to make the batch see my set commands?

Thanks

ZA


FishMonger
Veteran / Moderator

Jun 24, 2011, 12:44 PM

Post #2 of 8 (2406 views)
Re: [zatlas1] Executing 'set' Windows commend from Perl [In reply to] Can't Post

The system function runs your set command in a child process and once that process ends, so does the environment setting that was made in that child process.

If the environment variables are to be used in the batch file, then why not simply set them within the batch file?


zatlas1
Novice

Jun 24, 2011, 2:32 PM

Post #3 of 8 (2399 views)
Re: [FishMonger] Executing 'set' Windows commend from Perl [In reply to] Can't Post

Thank you

I was afraid that this would be the answer.

The idea was to set environment variables dynamically according to a parameter file. The only thing I could try to think about is to issue Perl Exec() command to execute the batch as a child, but I am not sure it would work either. Will test on Monday...

ZA


(This post was edited by zatlas1 on Jun 25, 2011, 7:03 PM)


FishMonger
Veteran / Moderator

Jun 24, 2011, 2:39 PM

Post #4 of 8 (2397 views)
Re: [zatlas1] Executing 'set' Windows commend from Perl [In reply to] Can't Post

Why not do everything in the Perl script and drop the batch file?


zatlas1
Novice

Jun 25, 2011, 7:01 PM

Post #5 of 8 (2363 views)
Re: [FishMonger] Executing 'set' Windows commend from Perl [In reply to] Can't Post

Sure,

That would be the easy solution, but I am only a lowly consultant (i.e. temp) in a 10B company, and even the employees who work with me do not have enough influence (or will) to change existing system in another facility. We may just modify the little piece we are working on. Frown

Thank you all


(This post was edited by zatlas1 on Jun 25, 2011, 7:02 PM)


rovf
Veteran

Jun 27, 2011, 12:25 AM

Post #6 of 8 (2308 views)
Re: [zatlas1] Executing 'set' Windows commend from Perl [In reply to] Can't Post

Setting the environment within Perl is easy:


Code
$ENV{NAME_OF_ENVIRONMENT_VARIABLE}='VALUE';



FishMonger
Veteran / Moderator

Jun 27, 2011, 8:21 AM

Post #7 of 8 (2290 views)
Re: [zatlas1] Executing 'set' Windows commend from Perl [In reply to] Can't Post

If the Perl only approach is not acceptable with your employer, then you can have the batch file parse the parameter file and setup the environment. I'm not a batch programmer, so I can't help in that area.

The method rovf shows for setting the environment variables is the best method within Perl, but those env settings are only good within the Perl script, which doesn't sound like an acceptable approach in your case.


zatlas1
Novice

Jun 27, 2011, 9:36 AM

Post #8 of 8 (2284 views)
Re: [FishMonger] Executing 'set' Windows commend from Perl [In reply to] Can't Post

Thank you again

I cannot do it from within Perl. I will look into parsing it in batch, but this would be on another forum

ZA

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives