Setting macro variables via a shell command

Hi

I want to set a variable in a macro by performing an action on a file in the shell directory. I can get the shell command working fine with a number of commands, but cannot figure out how to do anything other than print to the screen. Is what I want possible?

I have tried many things but initially thought:

Int_t j = 0;
j = gROOT->ProcessLine(" .!grep -c .root temp.files “);
or
j = gInterpreter->ProcessLine(” .!grep -c .root temp.files ");
or
j = gSystem->Exec("grep -c .root temp.files ");

cheers
Christian

Do

gROOT->ProcessLine(" .!grep -c .root temp.files > result ");

Cheers,
Philippe.

Thanks, but that only redirects output to a file and I’d hoped to set the macro variable directly. Is that possible, or should I just send to a file and read that?

cheers
Christian

Hi,
you must use
root.cern.ch/root/htmldoc/TSyste … m:OpenPipe
Few examples of its usage are in
root.cern.ch/root/htmldoc/src/TCondor.cxx.html

Regards. Valeriy

#include <stdio.h>

FILE* myProc = popen("/usr/bin/printf “Hello World!\n”", “r”);

char* output = char[100];
fgets(output, 100, myProc);

cout << output << endl;

popen should work just fine for this. Most implementations however aren’t bidirectional, so while grepping for several lines is an easy task with popen, if you were to specify “w+” as the type of the stream you’re opening you can’t expect bidirectional behavior to be portable.

-Jason Thomas.