I'm trying to convert some nasty Windows batch scripts into Perl, but I ran into a problem.
I know that when I run a Perl program, it gets its own environment, so changes made to variables disappear after the program's done. That's fine, I can live with that. But I just found out by experimentation (see code) that each call to system() also gets its own environment. Bugger.
Is there a way to force calls to system() to use the same environment as the main Perl program? If possible, I'd like to do this without modules outside the main Perl install, for easier distribution to those who'll be using it.
Here's my test code. When I run it, monkeylikes is always reported to be "bananas".
$ENV{'MonkeyLikes'} = "bananas";
print "$ENV{'MonkeyLikes'}\n";
system("echo %monkeylikes%");
system("set monkeylikes=flinging poo");
system("echo %monkeylikes%");
---
I'm too sexy for my .sig.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.