Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

config env script help building gradle from perl script (system/open tips needed)

by gj2666 (Beadle)
on Jun 11, 2013 at 15:53 UTC ( [id://1038284]=perlquestion: print w/replies, xml ) Need Help??

gj2666 has asked for the wisdom of the Perl Monks concerning the following question:

I inherited a win (2003) perl (5.16.2) build script combining steps in a build process for multiple apps. For one of the apps we build with Gradle.
I'm having a difficult time with the environment setup. Here's a snip...
if ($pvob eq "XYZ"){...} else { open("..\\abc-env\\setenv.cmd"); system(set); system("gradle"); ...}
I know that the open is in one (session/stream/fork/process?) and that as soon as it returns, all the environment it has just set is lost. I did the "system(set)" to confirm that point.
So when I execute the "gradle" it fails because there isn't anything in the env session where the system("gradle") is executed.
I read the "open()" perl doc and it looked like maybe you could create a pseudo filehandle that could be reused later in the calling script. But that sounded too good to be true. if so, syntax? Redirect or pipe new command into the filehandle?

I understand what open() or system() etc. is doing, but I've never really understood how to work with the configuration of such a temporary environment. The env is set for each build target so setting it at the os level doesn't really work for me in this case.

Any suggestions for getting the env variables to be persistent from within the build script would be appreciated.
(Or I suppose, help with syntax on stringing together the commands in the same open()?). This script has never worked for this app. (btw first thing I did was put in use strict and warnings so if you've taught me nothing, you've taught me that.)

  • Comment on config env script help building gradle from perl script (system/open tips needed)
  • Download Code

Replies are listed 'Best First'.
Re: config env script help building gradle from perl script (system/open tips needed)
by Corion (Patriarch) on Jun 11, 2013 at 17:11 UTC

    Why not simply write a batch file (using Perl) that invokes the environment setup, and afterwards invokes that gradle command?

    call ..\\abc-env\\setenv.cmd call gradle

    As an alternative, you could try a technique like Get default login environment except for Windows, and then stuff these changes into %ENV.

      I'm not sure I see how your suggestion is different than what I'm doing? Referencing PerlDoc I only see system(), ``, open(), and exec() as ways to execute commands in the shell. What am I missing?

        My suggestion is different because batch files executed by cmd.exe modify the environment of the cmd.exe process they are called in.

Re: config env script help building gradle from perl script (system/open tips needed)
by BrowserUk (Patriarch) on Jun 11, 2013 at 23:35 UTC

    If you set values into %ENV before calling system, then commands or programs run via system will see those changes,

    C:\test>set fred Environment variable fred not defined C:\test>perl -E"$ENV{fred}='bill'; system q[set fred]";; fred=bill

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Now at least that idea did not break my brain. Unfortunately the syntax will likely make me stabby. (been battling hashes of arrays syntax all morning. Hashes are hard like Lewisian Gneiss).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1038284]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-18 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found