Hi, We've always had to invent workarounds for the fact that ROOT doesn't pass the return value of macros back up to the shell. Matt Langston has also commented on this before: http://root.cern.ch/root/roottalk/roottalk00/2368.html I tried to look into the issue a little bit. First, plain "cint" behaves like I'd expect: # cint -x 'main() {exit(1);}' # echo $? 1 If you trace around long enough you find that ROOT (in TCint.cxx) is calling G__process_cmd, but the return value of that routine doesn't contain the return value of the macro, so the information just isn't there to be passed up the call stack. Probably the right thing to do is change things to use G__interpret_func (since that returns the value of interest), but that would take a bit of work. So, I tried just calling G__main in TRint::Run instead of ProcessLine to see what would happen, and that seems to work. One caveat is that the macro has to have a `main()' entrypoint, but that could be addressed pretty easily. Now I get the following: # echo "main(){exit(1);}" > main.C # root.exe -b -q main.C # echo $? 1 Clearly this isn't the best way to modify the sources to get this behavior, but it does work. Probably the right thing to do is modify the guts of TCint::ProcessLine to call the interpreter differently and change TApplication::ProcessLine to return a status and then change TRint::Run to call TApplication::Terminate(int) with that status value rather than a hardwired `0' as it does now. Whether it's also interesting to get that value passed from `root.exe' to `root' is another issue. In case it's of interest, I'm including a short patch with the changes I made. A change along these lines would be a big help, not just for running ROOT in batch jobs, but also for developing a ROOT test suite. Cheers, Dave diff -bru root.orig/rint/src/TRint.cxx root/rint/src/TRint.cxx --- root.orig/rint/src/TRint.cxx Tue Jun 13 14:49:00 2000 +++ root/rint/src/TRint.cxx Fri Dec 22 11:14:12 2000 @@ -197,13 +197,29 @@ { // Main application eventloop. First process files given on the command // line and then go into the main application event loop. - + Int_t result; Getlinem(kInit, GetPrompt()); // Process shell command line input files + result = 0; + if (InputFiles()) { TObjString *file; TIter next(InputFiles()); + + if (gROOT->IsBatch()) { + file = (TObjString *)next(); + char **argv; + char *argv0 = "cint"; + char argv1[256]; + argv[0] = argv0; + argv[1] = argv1; + Printf("\nProcessing %s...", (const char*)file->String()); + sprintf(argv1, "%s", (const char*)file->String()); + result = G__main(2, argv); + + } else { + RETRY { while ((file = (TObjString *)next())) { char cmd[256]; @@ -224,9 +240,12 @@ ProcessLine(cmd); } } ENDTRY; + } - if (QuitOpt()) - Terminate(0); + + if (QuitOpt()) { + Terminate(result); + } ClearInputFiles(); -- David Morrison Brookhaven National Laboratory phone: 631-344-5840 Physics Department, Bldg 510 C fax: 631-344-3253 Upton, NY 11973-5000 email: dave@bnl.gov
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:40 MET