Passing parameters to root in a script file

Hello all

I just learnt about the advantages of a compiles root file vs a interpreted root file. My question is about passing parameters to the code in a unix script file. 

How do I pass variables to the root file when I invoke it in a unix script. This did not work.

#! /bin/bash root -l -b -q << EOF .L add2num.C+ add2num(1,2,"test") EOF

Here is the root code:

[code]#include
#include
#include <sys/stat.h>
#include <math.h>
#include
#include
#include <stdio.h>
#include <time.h>
#include
#include
#include
#include

//ROOT stuff
#include <TRandom3.h>
#include <TH1.h>
#include <TFile.h>
#include <TTree.h>
#include “TStopwatch.h”

void add2num (int a, int b, char configfile[256]) {
printf(“Ans = %i\n”,a+b);
printf(“Config file = %s”,configfile);

FILE *config=fopen(configfile,"r");
Int_t 		FILESTOREAD=0;
char		outputlistmodefile[256];

fscanf(CONFIG,"%i",&FILESTOREAD);
fscanf(CONFIG,"%s",outputlistmodefile);

fclose(config);

}[/code]

Thanks in advance

do

root -b -q 'add2num.C+(1,2,\"test\")'
see more examples in the first 2 pages of the Getting Started Manual at
ftp://root.cern.ch/root/doc/2GettingStarted.pdf

Rene

Thanks Rene. On page 9, it says you can build a shared library. Can you explain how I use this?

#include <iostream> ... ... #include <TTree.h> void expt1 () { printf("Test\n"); }

~/root_test> root -l -b -q expt1.C+ root [0] Processing expt1.C+... Test

creates the shared lib file expt1_C.so, but how do you execute it again.

I tried

~/root_test> root -l -b -q expt1_C.so root [0] Processing expt1_C.so... Error: Function expt1_C() is not defined in current scope :0: *** Interpreter error recovered ***

[quote]creates the shared lib file expt1_C.so, but how do you execute it again. [/quote]The same way :slight_smile:

~/root_test> root -l -b -q expt1.C+The library will be recompiled only if it is needed.

Cheers,
Philippe