problems with function system

  • Thread starter Christian Christmann
  • Start date
C

Christian Christmann

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 " + locationOfScrtip;"
[locationOfString 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
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Christian said:
The shell script is setting paths with "export PATH=/home/test/gcc/" .
When within my program I use
"string sysCall = "source " + locationOfScrtip;"
[locationOfString 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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top