TApplication ignores command line macros

I created a simple standalone executable that uses a TApplication.
It does show the help if I “./myapp -h”, but it completely ignores given macros if I “./myapp -q mymacro.C” (actually, it also ignores the “-q”).

Probably, you should use TRint class

I do not really want to create any “interactive” interface.
I just need the standard TApplication to behave (i.e., respect command line options shown by “-h”).

I would say - -h have to show correct message for TApplication and remove unsupported features.

Hi @Wile_E_Coyote,

The TApplication class constructor parses the command line arguments, but does not automatically take any action. The user is responsible for implementing behavior. The following excerpt show provide you the starting point to attain what you want.

#include <TApplication.h>
#include <TObjArray.h>
#include <TObjString.h>

int main(int argc, char *argv[]) {
        TApplication app("app", &argc, argv);
        TIter iter(app.InputFiles());

        while (TObjString *i = (TObjString *)iter()) {
                if (!i->TestBit(TApplication::kExpression))
        return 0;


@jalopezg Thanks for your reply. Your example is ROOT 6 specific (it uses “TApplication::kExpression”).

Actually, I also implemented a very similar simple piece of code (which works in any ROOT version):

#include "TApplication.h"
#include "TString.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "TCollection.h"

int main(int argc, char **argv)
  // make sure that the autoloading of ROOT libraries works
  TApplication *a = new TApplication("MyApplication", &argc, argv);
  if (a->InputFiles()) { // process command line macro files
    TIter n(a->InputFiles());
    TObjString *f;
    while ((f = (TObjString *)n())) a->ProcessFile(f->String());
  if (a->QuitOpt()) return 0; // "-q" was given so exit now
  // ...
  return 0;

BTW. I think it’s a shame that the TApplication does not process command line arguments (except “-n”, of course).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.