in reply to Persistent environment (Windows)

Is there a way to force calls to system() to use the same environment as the main Perl program?

I am confused. To me, your test shows that the calls to system() inherit the environment from the main Perl program, but that changes made to the environment inside the system() call do not propagate back into the Perl program's environment.

Dave Roth's book Win32 Perl Scripting, Chapter 6, has a section on 'Modifying the User Environment', which might be worth a glance. He shows how to set permanently e.g. $ENV{'MonkeyLikes'}, using his module Win32::AdminMisc - close, but different from what you want to do.

Rudif

PS. By an amazing coincidence, the Chapter 6 of Dave's book is available online at the above URL as a sample chapter.

Replies are listed 'Best First'.
Re: Re: Persistent environment (Windows)
by idnopheq (Chaplain) on Apr 10, 2001 at 16:49 UTC
    This is correct. The line
    system("set monkeylikes=flinging poo");
    sets %monkeylikes% for that system call only. You would need Win32::AdminMisc to set the variable permanently, or do
    $ENV{'MonkeyLikes'} = "bananas"; print "$ENV{'MonkeyLikes'}\n"; system("echo %monkeylikes%"); $ENV{'MonkeyLikes'} = "flinging poo"; system("echo %monkeylikes%");
    for on-the-fly while-the-script-executes kind-of stuff. It yields

    bananas
    bananas
    flinging poo

    I believe from the parent post that this is what you are looking for, but that is just my opinion. I could be wrong.

    HTH
    Dex