Calling root script inside another root script

Dear all,

It might be a C++ related question but it is specific to root, so I thought to post here for help.

I have many root scripts, each plots a histogram. I want to call these scripts inside another root script to plot all histograms in one canvas. Calling each script separately works fine, but I want to loop over the scripts (because there many scripts) and gSystem->Exec(scriptName.c_str()) does not works. Below is the sample code:

The separate scripts are plot1.C, plot2.C, …, plot20.C. I want to call them from draw.C.

Working script:

#include "plot1.C"
#include "plot2.C"
..
..
#include "plot20.C"

void draw()
{
        TCanvas *c1 = new TCanvas("c1", "c1", 800, 800);
        c1->Divide(5, 4, 0, 0);

        c1->cd(1);
        plot1();

         c1->cd(2);
         plot2();
         .......
         .......
         c1->cd(20);
         plot20();
}

Not working script:

#include "plot1.C"
#include "plot2.C"
..
..
#include "plot20.C"

void draw()
{
        TCanvas *c1 = new TCanvas("c1", "c1", 800, 800);
        c1->Divide(5, 4, 0, 0);

        char ch[200];
        for(int i=1; i<=20; i++) {
                sprintf(ch, "%d", i);
                c1->cd(i);
                string name = "plot" + string(ch) + "()";
                gSystem->Exec(name.c_str());
        }
}

Error : sh: -c: line 1: syntax error: unexpected end of file

Any help?

Thanks.

Try (“gROOT” or “gInterpreter”): gROOT->ProcessLine(name.c_str()); or if you do not #include “plot*.C” files: string name = ".x plot" + string(ch) + ".C()"; gROOT->ProcessLine(name.c_str());

I changed gSystem->Exec(name.c_str()) by gROOT->ProcessLine(name.c_str()) as you suggested but keeping all other same and it works. Thanks.

[quote]gSystem->Exec(name.c_str());[/quote]This is to execute a shell command (i.e. what you can use in tcsh, bash, etc.), and not for a C++ statement.

Cheers,
Philippe.