Assigning shell command output to a variable in ROOT

600 views Asked by At

I am executing a shell command in my ROOT code using gSystem which returns an int, as seen here gSystem->Exec(). But when I try to assign the output to a in code variable the assignment doesn't happen.

int low_edge = 0;
low_edge = gSystem->Exec("ls ./folder | egrep -o '[0-9]{3,3}' | head -1");

I have tried also gSystem->Exec("ls ./folder | egrep -o '[0-9]{3,3}' | head -1") >> low_edge, but it didn't work out.

Am I missing something obvious?

1

There are 1 answers

1
Asen Christov On BEST ANSWER

The return value of gSystem->Exec() is 0 or -1 depending on if the command was successful.

What you want is:

TString GetFromPipe(const char* command)

TString the_output=gSystem->GetFromPipe("ls ./folder | egrep -o '[0-9]{3,3}' | head -1");

should work, you just need to convert TString to int.