IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Perl, system, backticks, and environment variables
Situation:

Perl script needs to call a shell script (that is not under programmer control; ie. we can't change it to do our evil bidding). When that script is done, it will have set several environment variables. Is it possible to obtain those environment variables after the script runs, and how?

Workaround is to run the script before the perl script, but in this situation that's a messy hack. I also made the suggestion to the guy working on it that he could call a script in the same system call after the initial script, and have the second script print out or otherwise return the environment variables in some fashion. That's a messy hack as well.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Check out %ENV
Quick check of [link|http://www.perlmonks.org/index.pl?node_id=105795|PerlMonks] uncovered this. Might help, might not...

Check that after you call the other script, of course...

And, IIRC, you can call the other script via the system() call...
-YendorMike

[link|http://www.hope-ride.org/|http://www.hope-ride.org/]
New %ENV not set by subprocesses.
Which is exactly the problem. :-)
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Re: %ENV not set by subprocesses.
Why don't you just parse the other script and look for the set statements (setenv, export, whatever)? Dunno perl, but in rexx, you could do something like this:
envsource = .stream~new(somescript.cmd)\nlines = envsource~makearray\ndo i = 1 to lines~lines\n   if lines[i]~word(1) = "set"\n      then do\n      parse var lines[i] . envvar '=' newval\n      value('OS2ENVIRONMENT', envvar, newval)\n      end /* End if */\n   else iterate\nend /* End do loop */\ndrop lines\nenvsource~close

Note that I haven't actually tested this, but should give you the general idea. It assumes you can read the file, of course, but if you can execute it I'm sure you can read it. Sure, it's an ugly hack, but it would work, and would permit you to let someone change the file without worrying about it breaking your program.
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
New That assumes the values aren't calculated.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Perhaps I'm dense.
I'm just curious - ignore this if it requires TMI.

As I understand the situation, you've got a script S that does some stuff and before exiting sets some environment variables. Those environment variables are persistent. You want to write a Perl script that calls S and be able to read those environment variables in the Perl script (or afterwards). But you can't do so with the Perl script because of subprocess limitations. Correct?

But you say,

Workaround is to run the script before the perl script, but in this situation that's a messy hack.

How so? It seems to me that it's the best solution if you can't change script S. It sounds like the [link|http://z.iwethey.org/forums/render/content/show?contentid=25831|transparent aluminum mirror] problem again... ;-)

Cheers,
Scott.
New This is a CGI perl script
Which means that we'd have to call another script first, which calls the environment variables script, and then calls the perl script.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Parent-child environment inheritence

Parent don't inherit the child's environment. I'm assuming a Unix-like OS.

\r\n\r\n

Your options IMO are:

\r\n\r\n
    \r\n
  • Have the child report its environment to the parent.
  • \r\n\r\n
  • Determine the child's environment by other means. /proc/pid/env contains this information in Linux.
  • \r\n\r\n
  • Vague possibility: wrap the script in another process which manages it in a way that the environment is determinable. You'd probably have to intercept shell/system calls to do this.
  • \r\n\r\n
  • Make the script do your evil bidding. If it is indeed a shell script, you can modify the startup and/or exit via .bashrc and .bash_logout files. If you can control the effective userid of the script, you may be able to change its startup shell in /etc/passwd. Or you can require modules be run by whomever it is which writes the script. Or intercept the script and modify it prior to submission....
  • \r\n\r\n
\r\n\r\n

HTH

--\r\n
Karsten M. Self [link|mailto:kmself@ix.netcom.com|kmself@ix.netcom.com]\r\n
[link|http://kmself.home.netcom.com/|http://kmself.home.netcom.com/]\r\n
What part of "gestalt" don't you understand?\r\n
[link|http://twiki.iwethey.org/twiki/bin/view/Main/|TWikIWETHEY] -- an experiment in collective intelligence. Stupidity. Whatever.\r\n
\r\n
   Keep software free.     Oppose the CBDTPA.     Kill S.2048 dead.\r\n[link|http://www.eff.org/alerts/20020322_eff_cbdtpa_alert.html|http://www.eff.org/alerts/20020322_eff_cbdtpa_alert.html]\r\n
New In the script report ENV and parse that in the caller
You might get some ideas on how to do that from [link|http://www.perlmonks.org/index.pl?node_id=33628|this hack] I wrote for figuring out your login environment.

Cheers,
Ben
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Can't do that.
We don't control the script that is being called. The rest looks good, though. Thanks, I'll pass it on.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
Expand Edited by admin May 12, 2003, 05:46:50 PM EDT
New How about writing a wrapper for the script that sources it?
something along the lines of
\n. origScript.sh\necho $env1\necho $env2\n
--

Less Is More. In my book, About Face, I introduce over 50 powerful design axioms. This is one of them.

--Alan Cooper. The Inmates Are Running the Asylum
New It's a CGI script
that needs to call a setenv script.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New I guess I don't know CGI ...
What is setenv script?
--

Less Is More. In my book, About Face, I introduce over 50 powerful design axioms. This is one of them.

--Alan Cooper. The Inmates Are Running the Asylum
New bash script?
New Perl CGI calling base environment script.
The idea is to use a standard system env. setup script in a cgi program to set up things like database SID, etc.

I think he finished his work around a good month ago, though, so I'm a little bemused by the attention being lavished here now. :-)
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New WAG
call a perl module calle expect,
call it get what you want return processing to the shell\\
long way around
thanx,
bill
will work for cash and other incentives [link|http://home.tampabay.rr.com/boxley/resume/Resume.html|skill set]

questions, help? [link|mailto:pappas@catholic.org|email pappas at catholic.org]

As the Poets have mournfully sung.
Death takes the innocent young,
The rolling in money,
the screamingly funny,
And those who are very well hung.
W.H. Auden
     Perl, system, backticks, and environment variables - (admin) - (15)
         Check out %ENV - (Yendor) - (3)
             %ENV not set by subprocesses. - (admin) - (2)
                 Re: %ENV not set by subprocesses. - (jake123) - (1)
                     That assumes the values aren't calculated. -NT - (admin)
         Perhaps I'm dense. - (Another Scott) - (1)
             This is a CGI perl script - (admin)
         Parent-child environment inheritence - (kmself)
         In the script report ENV and parse that in the caller - (ben_tilly) - (7)
             Can't do that. - (admin) - (6)
                 How about writing a wrapper for the script that sources it? - (Arkadiy) - (4)
                     It's a CGI script - (admin) - (3)
                         I guess I don't know CGI ... - (Arkadiy) - (2)
                             bash script? -NT - (ChrisR) - (1)
                                 Perl CGI calling base environment script. - (admin)
                 WAG - (boxley)

Enthusiasm substituting for real talent.
141 ms