Re: shellscript executing a root macro with variables

From: Tom Roberts <tjrob_at_fnal.gov>
Date: Fri, 09 Mar 2007 19:46:39 -0600


John Zoidberg wrote:
> I would like to create a shellscript which can take any ROOT macro (with
> 0,1 or more variables) as argument, launch root, execute the macro with
> the given arguments and write the output into a .out file and the errors
> into a .err file.

Here's how I pass arguments to my Root macro (this is a bash script): ARGS="$*" $ROOTSYS/bin/root -n -l macro.C

The ARGS are names of Root files to read:

         // open files given in environment variable ARGS
         const char *args = gSystem->Getenv("ARGS");
         if(!args) args = "";
         TObjArray *files = TString(args).Tokenize(" \t");
         for(int i=0; i<files->GetEntries(); ++i) {
                 TObjString *s = files->At(i);
                 if(!s || *s->String().Data() == '\0') continue;
                 TFile *f = new TFile(s->String().Data(),"READ");
                 if(f->IsZombie())
                         new TGMsgBox(gClient->GetRoot(),window,"Error",
                           "File could not be opened!"); //self-deleting
         }
         files->Delete();
         delete files;

Yes, this fails if any filename contains a space....

Tom Roberts Received on Sat Mar 10 2007 - 02:46:50 CET

This archive was generated by hypermail 2.2.0 : Sat Mar 10 2007 - 11:50:01 CET