How to find if something went wrong in processing or parsing

Hello,

I would like to automatize in a script the simple detection of errors in the ROOT interactive shell.
Hoe can I know if the last command had a wrong syntax (e.g. “WHILE (true);”) or if the last CINT command (e.g. “.L myMacro.C+”) has failed?

Thank you!

Hi,

I don’t know how you want to interact with the shell. Depending on that my answer might differ :slight_smile: EE.g. you could use TInterpreter::ProcessLine() which allows you to retrieve the error code.

Cheers, Axel.

Well, the easiest way for me would be to enter directly the commands through CINT:

.L myMacro.C+ // check if something went wrong... inr i = 0; // check that something went wrong...

I hoped there was a gInterpreter method to retrieve the status of the last operation, but I couldn’t find any (TInterpreter::GetExitCode() doesn’t).

The alternative you suggest is to call the interpreter object to process every single line.
Would that be like:

TInterpreter::EErrorCode CINTerror = 0; gInterpreter->ProcessLine(".L myMacro.C+", &CINTerror); if (CINTerror != TInterpreter::kNoError) { std::cerr << "Bad dog!!!" << std::endl; exit(CINTerror); } gInterpreter->ProcessLine("inr i = 0;", &CINTerror); if (CINTerror != TInterpreter::kNoError) { std::cerr << "Bad dog!!!" << std::endl; exit(CINTerror); }
?
In both cases, the text in the code tag would be passed to root.exe through a pipe.

Hi,

To get the error from ACLiC, you can call directly TSystem::CompileMacro:int i = gSystem->CompileMacro("myMacro.C","k");where 0 indicates failure.

To catch the output, you will need to redirect stdout and stderr to a file and look at the file. The simpliest being the following:int result = gROOT->ProcessLine("gSystem->CompileMacro(\"myMacro.C\",\"k\"); >& build.log ");

Cheers,
Philippe.