Hello, Environment variables are local to each *process*, they inherit the them from their parent when a process is created. If a process modifies its environment variables it is only visible in that process and possibly in any child process it creates. A common way to get values from a sub process is using pipes. They are available through the functions TSystem::OpenPipe() and TSystem::ClosePipe(). You can either write to the standard input of the sub process or read from the standard output. OpenPipe() returns a "C" library FILE pointer that can be used with fgets() to read the data (or fprintf() if you need to provide input) Regards, Marten. On Fri, 2003-08-01 at 09:26, Valeri Fine wrote: > Hello, > You may try > > http://root.cern.ch/root/htmldoc/TSystem.html#TSystem:Setenv > > method to set that. > > However this is still shell specific. > I think it is not a good idea to provide the communication between two > processes via the shell env variable. It looks simple but it is error > prone. > > I agree with Olivier's statement > "I guess you should find another way to send the run number outside > ROOT" > > Best regards, Valeri > > > -----Original Message----- > > From: owner-roottalk@pcroot.cern.ch > [mailto:owner-roottalk@pcroot.cern.ch] > > On Behalf Of Olivier Couet > > Sent: Friday, August 01, 2003 5:25 AM > > To: Meiwen > > Cc: rt > > Subject: Re: [ROOT] help > > > > > > Hello, > > > > I think your problem comes from the fact that gSystem->Exec starts a > new > > shell. So your variable is defined during the short time this new > shell > > is alive but then doesn't exist in the shell in which ROOT started. In > > order to demonstrate this effect I have created the following very > simple > > example: > > > > --- file runnb.C > > { > > gSystem->Exec("export AAA=hello"); > > printf("%s\n", gSystem->Getenv("ROOTSYS")); > > printf("%s\n", gSystem->Getenv("AAA")); > > } > > --- > > > > The output of this macro is: > > > > root [0] .x runnb.C > > /home/couet/rootpro > > > > root [1] > > > > as you see the variable ROOTSYS is known because it was set in the > shell > > in which ROOT started, but AAA is blank because the shell in which it > was > > set finished. I guess you should find an other way to send the run > number > > outside ROOT. May be write it into a file ? > > > > Cheers, Olivier > > > > > > On Fri, 1 Aug 2003, Meiwen wrote: > > > > > Dear rooters > > > I need to get the value of parameter Run_Number and have > written a > > small test program as following: > > > > > > { > > > gROOT->Reset(); > > > char *RUNNR = new char[100]; > > > > > > sprintf(RUNNR, "export Run_Number=`getvalue runctl@krunc runnr | > grep > > value | awk '{print $3}'`"); > > > > > > gSystem->Exec(RUNNR); > > > > > > cout << "Run_Number = " << gSystem->Getenv("Run_Number") << endl; > > > > > > > > > } > > > > > > The problem is the result of Run_Number is empty. But when I > executed > > the command > > > > > > export Run_Number=`getvalue runctl@krunc runnr | grep value | awk > > '{print $3}'` > > > echo $Run_Number > > > > > > I got the real value Run_Number. Could you help me? > > > > > > thanks a lot Wen > Mei > > > > > > > -- > > Org: CERN - European Laboratory for Particle Physics. > > Mail: 1211 Geneve 23 - Switzerland Mailbox: > J25910 > > E-Mail: Olivier.Couet@cern.ch Phone: +41 > 22 > > 7676522 > > WWW: http://cern.ch/Olivier.Couet/ Fax: +41 > 22 > > 7677155 -- Maarten Ballintijn <maartenb@mit.edu> Massachusetts Institute of Technology
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET