Bug in TRint::Run

Hi,

If you run the following code the program falls into an endless loop in the second call of app->Run(true);

#include <TRint.h>
int main(int argc, char *argv[])
{
TRint *app = new TRint(“App”, &argc, argv,NULL,0,true);
app->Run(true);
app->Run(true);

return 0;
}

I’m using version 5.02.00 on windows.

Matthias

Hi,
Modify your code as shown below :

[code]#include <TRint.h>
#include <TSystem.h>

int main(int argc, char *argv[])
{
TRint *app = new TRint(“App”, &argc, argv,NULL,0,true);
app->Run(true);
gSystem->Init();
app->Run(true);
return 0;
}[/code]HTH,
Bertrand.

Thanks for that.

The problem is that with gSystem->Init() I loose all my variables I have defined in the first session.

In the following example I would like that the second cout statement prints out 5.

#include <TRint.h>
#include <TSystem.h>

int main(int argc, char *argv[])
{
TRint *app = new TRint(“App”, &argc, argv,NULL,0,true);
app->ProcessLine(“int i = 5;”);
app->ProcessLine(“cout << i << endl;”);
app->Run(true);
gSystem->Init();
app->ProcessLine(“cout << i << endl;”);
app->Run(true);
return 0;
}

Matthias

Hi Matthias,

This is the expected behaviour (try on linux)…
May I ask what you want to do exactly ?
TRint is mainly used to run macros, or interpreter commands, and I don’t see the reason to exit from a session (app->Run(true)) to fall back into another one.

Cheers,
Bertrand.

Hi Bertrand,

I would like to use the root interpreter inside a program which is not base on root. I would like to run root macros and also let the user start an interactive session at certain points in my program. But of course I don’t want to loose all the data that was created during the session.

In my opinion it should be possible to use the root interpreter as a function inside an other program.

For example imagine you have a graphical userinterface not based on the root libraries. Now you want to have a button “start root session” which should just start an interactive root session and a button “start macro XXX” which runs a macro. Now it should be possible to call TRint::Run and after that execute the macro with TRint::ProcessLine and maybe start TRint::Run again.

Cheers,
Matthias

Hi Matthias,

Sorry, but the variables will be known by the interpreter as long as you don’t quit.
Mixing Root and other programs can be done, but depending of the functionalities you want to have, it may require a lot of code (especially on windows).

Cheers,
Bertrand.

The problem of infinite loop has been solved in current CVS Version.
Your first example :

[code]#include <TRint.h>
#include <TSystem.h>

int main(int argc, char *argv[])
{
TRint *app = new TRint(“App”, &argc, argv,NULL,0,true);
app->Run(true);
app->Run(true);
return 0;
}[/code]
works now without the need to insert the gSystem->Init() line.

Cheers,
Bertrand.