Using Command Line Arguments in Symbian

Login to reply to this topic.
Fri, 2005-07-15 12:02
Joined: 2005-06-24
Forum posts: 5
Most Symbian programs are launched through a graphical shell rather than through a command-line.
The common exceptions are .exes on the PC platform, which can be run from a Windows command prompt.
For .exe programs, control is received through the E32Main() function, which, however does not supply arguments. Instead, access to arguments is provided by CCommandLineArguments
Conventional C and C++ programs receive their arguments from main(int argc, char* argv[]).
On Symbian OS, programs are invoked through an E32Main() function taking no arguments.
For a program that is launched as a new process, the arguments are available as part of the process command line and may be obtained in full using code such as
RProcess me;
TPtrC program=me.FileName();
TPtrC args=me.CommandLine();
However, the arguments are in a raw form. For convenience, the CCommandLineArguments class provides functions to access the program name as argument 0, and each command-line argument as argument 1, 2 etc.
Arguments beginning with a quote may contain blanks and doubled quotes.
Arguments not beginning with a quote are terminated by a blank.

void ReadAndWriteArgsL()
   {
   console=Console::NewL(_L("Command-line arguments reader test"), TSize(KConsFullScreen, KConsFullScreen));
   CleanupStack::PushL( console );
   //Create CommandLine Arguments and read it.
   CCommandLineArguments* args=CCommandLineArguments::NewLC();
   for (TInt i=0; i<args->Count(); i++)
      {
      TPtrC argumentPrt(args->Arg(i));
      console->Printf(_L("Arg %d == %S\n"), i, &argumentPrt);
      }
   CleanupStack::PopAndDestroy(2);
   }

GLDEF_C TInt E32Main()
    {
   __UHEAP_MARK; // mark heap state
   CTrapCleanup* cleanup=CTrapCleanup::New();
   TRAPD(error, ReadAndWriteArgsL());
   __ASSERT_ALWAYS(!error, User::Invariant());
   delete cleanup;
   __UHEAP_MARKEND;
   return 0;
    }


If Application Name is TestCmdArgs.exe, launch it as TestCmdArgs.exe Nokia India Pvt Ltd from command prompt
And the output will be

Arg 0 == TestCmdArgs.exe
Arg 1 == Nokia
Arg 2 == India
Arg 3 == Pvt
Arg 4 == Ltd

Regards
Girish

Girish Shetty


Fri, 2005-07-15 12:14
Joined: 2005-03-06
Forum posts: 183
Re: Using Command Line Arguments in Symbian
Fasinating.

How do you pass in the arguments (in the call)  if you are calling the "exe" from within an App or another exe for example rather than from the command line?

Regards,
Isseyp
  • Login to reply to this topic.