Re: gSystem->Exec() : memory of variables

From: Marc Escalier <escalier_at_lal.in2p3.fr>
Date: Wed, 9 Mar 2011 12:41:31 +0100


thank you Dario

Dario Berzano a écrit :
> Hello,
>
> each gSystem->Exec(), just like the standard C system() function, opens a new shell ("man system" says /bin/sh) with a brand new environment.
>
> But in ROOT you can set environment variables that are seen by subshells launched either via gSystem->Exec() or gSystem->OpenPipe()/GetFromPipe(): for instance you can play with the following code:
>
> // The environment variable COUNTER is set to 0
> gSystem->Setenv("COUNTER", "0");
>
> // COUNTER is incremented in subshells and its value is set to ROOT's
> // (*not* shell's) environment
> for (Int_t i=0; i<100; i++) {
> gSystem->Setenv("COUNTER", gSystem->GetFromPipe("expr $COUNTER + 1"));
> }
>
> // A subshell is spawned to echo the value of envvar COUNTER
> gSystem->Exec("echo Variable COUNTER has value $COUNTER");
>
> Please note that opening/closing 100 subshells just to increment a variable's value 100 times isn't very performance-friendly...
>
> Cheers,
> --
> : Dario Berzano
> : INFN & Università - Torino, Italy
> : Wiki: http://newton.ph.unito.it/~berzano
> : GPG: http://newton.ph.unito.it/~berzano/gpg
> : Mobile: +39 348 72 22 520
>
>
> Le 9 mars 2011 à 11:53, Marc Escalier a écrit :
>
>
>> Hello,
>>
>> in root, there are the methods TSystem::Exec() and TSystem::GetFromPipe which have the same behaviour for the following issue :
>>
>> if one does in unix :
>> a=3
>> echo $a
>> it works
>>
>> but in root :
>> if ones does :
>> gSystem->Exec("b=3);
>> gSystem->Exec("echo $b")
>> it will "forget" the b
>>
>> only this works :
>> gSystem->Exec("c=3;echo $c")
>>
>> ==>
>> is there a way to have the memory of the variables for several gSystem->Exec() commands ?
>> (in order to do some instructions ones, and some others inside a loop)
>>
>> (i tried also with export, but it doesn't help)
>>
>> thanks
>>
>
>
>
Received on Wed Mar 09 2011 - 12:43:40 CET

This archive was generated by hypermail 2.2.0 : Wed Mar 09 2011 - 17:50:01 CET