Re: Help with 'system' seeming to return too soon...

From: Arne Jamtgaard (ajamtgaa_at_cisco.com)
Date: 09/13/04


Date: Mon, 13 Sep 2004 13:45:43 -0600

Scott W Gifford wrote:

> Arne Jamtgaard <ajamtgaa@cisco.com> writes:
>>I've got a script that, among other things, needs to source a
>>file to set a bunch of environment variables before it runs an
>>install script. Once the install is complete, the script uses
>>the installed files to do some more configuration steps.

> That's likely to be part of your problem. Each system() command is
> executed in a new process, so when you do system(". file"), it creates
> a new process, sets the environment variables in that process, then
> that process exits; the environment in your program is unaffected, and
> the environment in all future system calls is unaffected. To fix
> this, You can either turn this into one shell command or shell script,
> or else parse vpnenv.sh yourself and set %ENV appropriately.

I had hoped by stringing the commands together with semicolons (like
I can on the command line) that I could get around this problem. So
even though they are all quoted together, 'system' will pull each
command off separately and run them in individual shells? Dang.

That's why I kept tacking on the source command - one shell per
quoted line, as opposed to one per command.

This has got to be a problem that others have surmounted - how can
you use 'system' to run a command with a bunch of environment
variables already set?

Arne



Relevant Pages

  • Re: Possible to define a variable for only certain directories?
    ... allows such customizations upon the environment on a per- ... this is useful only if the user or script ... configuration files, environment variables, command line options, and ... commands to the CDE Window Manager from a shell ...
    (comp.unix.shell)
  • Re: user id validation
    ... I have not tried like that but I feel it can be done because the environment ... Rajnikant Jachak | Software Engg | Persistent Systems Limited ... I am just wondering how to validate a user who is using the script?? ... there specific perl command for that? ...
    (perl.beginners)
  • Re: Script export problem in FC3
    ... > I need to modify the PATH environment using a script. ... > If I run the export command in command line I have no problem, ... The child process has the new environment, ...
    (Fedora)
  • [REVS] Using Environment for Returning Into Lib C
    ... This article explains how to use the environment variables to successfully ... The environment will consequently be used to store it. ... It is easy to write a simple program to put the command directly into the ... declare -x COLORTERM="" ...
    (Securiteam)
  • Re: rm -r /usr/local by mistake
    ... (i.e. act the _same_ way, for the same invocation, in any environment). ... In the non-interactive language there is *no* "rm' command, ... So in a noninteractive script, ... Do you understand that "would have to specify the 'non-interactive' flag" ...
    (comp.unix.bsd.freebsd.misc)