Re: Processing Macros in background

From: Thomas Lauf <thl_at_hll.mpg.de>
Date: Tue, 6 Jul 2010 10:53:20 +0200


Hello Axel, Rooters!

My idea at the moment is to implement an option for my program which determines whether to start it as an TRint (interactive) or just as a simple TApplication. In the first case I have my command line user interface, the second is for the special case described below.

The small example below does the job, the price is that I have to trigger the execution of the macro files manually. But this seems to solve my problem, so I pay it willingly :)

main.cxx:
#include "TSystem.h"
#include "Riostream.h"
#include "TMacro.h"
#include "TApplication.h"
#include "TRint.h"
#include "TObjArray.h"
#include "TObjString.h"

Int_t main( Int_t Argc, Char_t** Argv ) {

   Bool_t Interactive=kTRUE;

   for( Int_t i=0; i<Argc; ++i ) {

     cout << "Arg[" << i << "]: " << Argv[i] << endl;
     if( !strcmp(Argv[i], "-noninteractive") ) Interactive=kFALSE;
   }         

   TApplication* theApp;         

   if( Interactive ) {

     cout << "--- interactive mode ---" << endl;
     theApp = new TRint( "App", &Argc, Argv );
   } else {
     cout << "--- non interactive mode ---" << endl;
     theApp = new TApplication( "App", &Argc, Argv );
   }

   cout << "Running..." << endl;
   if( Interactive ) {
     theApp->Run( kTRUE );

   } else {

     cout << "Processing input files..." << endl;
     TIter Next( theApp->InputFiles() );
     TObjString* ObjStr;

     while( (ObjStr = (TObjString*) Next()) ) {
       theApp->ProcessLine( Form( ".x %s", ObjStr->String().Data() ) );
     }		

   }
   cout << "Quitting..." << endl;
}

Test.C
{

   #include "Riostream.h"
   cout<< "Hello World" << endl;
}

One thing that still puzzels me is: if background processes cannot write to the TTY, why do I see the ROOT Logo when doing this:

]> root -b &

The output stops when the ROOT prompt would be displayed. Guess I have to update my understanding of "tty" and "standard output". Until now this was identical for me...

Thanks for the help so far!

Thomas

Axel Naumann wrote:

> background processes cannot write to the TTY. If you have an idea (or a
> patch! :-) how to get it to work nevertheless then please let us know.
> 
> Cheers, Axel.
> 
> Thomas Lauf wrote on 07/05/2010 04:59 PM:
>> Hello ROOTers,
>>
>> is there a way to process a ROOT macro in the background?
>>
>> Consider this simple macro Test.C:
>> {
>>   cout << "Hello World" << endl;
>> }
>>
>> If I call ROOT to process it
>> ]> root -q -l Test.C
>>
>> in the shell I get the expected output:
>>
>> root [0]
>> Processing Test.C...
>> Hello World
>> ]>
>>
>> But if I want ROOT to process it in the background
>> I get no output until I fetch the process to foreground again
>> ]> root -q -l Test.C &
>> [4] 16584
>> ]> fg
>> root -q -l Test.C
>> root [0]
>> Processing Test.C...
>> Hello World
>> ]>
>>
>> Is there a way to make this work?
>>
>> The thing is I have a application (e.g. Prog1) which calls another one
>> (e.g. Prog2) to do some calculation. Prog2 uses Rint as user interface.
>> The call from Prog1 succeeds as long as it is run in foreground. If run
>> in the background I run into the same problem as shown above.
>>
>> Regards
>>
>> Thomas Lauf
Received on Tue Jul 06 2010 - 10:53:58 CEST

This archive was generated by hypermail 2.2.0 : Tue Jul 06 2010 - 11:50:01 CEST