problems with function system

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Christmann

    problems with function system

    Hi,

    I have some problems with invoking a shell script out of a c++ program.
    The shell script is setting paths with "export PATH=/home/test/gcc/" .

    When within my program I use
    "string sysCall = "source " + locationOfScrti p;"
    [locationOfStrin g is a string containing the location of the script] and
    "system( sysCall.c_str() );"

    the paths are not set. When I run the script in bash with
    "source pathToScrtip" the paths are set correctly .
    Any ideas how to solve that problem?

    Thanks
    Chris
  • Julián Albo

    #2
    Re: problems with function system

    Christian Christmann wrote:
    [color=blue]
    > The shell script is setting paths with "export PATH=/home/test/gcc/" .
    > When within my program I use
    > "string sysCall = "source " + locationOfScrti p;"
    > [locationOfStrin g is a string containing the location of the script] and
    > "system( sysCall.c_str() );"
    > the paths are not set. When I run the script in bash with
    > "source pathToScrtip" the paths are set correctly .
    > Any ideas how to solve that problem?[/color]

    The usual way to use the environment in the operating systems is: each
    process has his own environment, when creating a process his environment is
    created by copying from the parent, when the child finishes his environment
    is destoyed.

    Your script sets the environment of the child process that runs int, it does
    not touch the environment of the process that is running your program.

    Or in a shorter way: you can't do that.

    --
    Salu2

    Comment

    Working...