Passing command line arguments to an Aion application

Document ID : KB000028190
Last Modified Date : 14/02/2018
Show Technical Document Details

You can pass command line arguments to an Aion application by creating a _TaskInitialize method in the Entry class of the application and thenadding a string input argument to this method. The command line argumentswill be passed into this string input argument.

For example, let's say you have an Aion applicationthat connects to a database and you want the application users to pass intheir database userid and password with arguments /U and /P. To do this,you might have your _Taskinitialize method (in your Main class) asfollows:

Method: _Taskinitialize

IN cmdline is string

Method Body:

// extract userid
var loc1, loc2 integer
loc1 =index(cmdline,"/U")
if loc1 > 0 then
   // findwhere argument ends (at a space)
   loc2 =index(cmdline," ",loc1)
   if (loc2 = 0)then
      loc2 = length(cmdline) +1
   loc1 = loc1+2
     // get the userid
   UserID =substring(cmdline,loc1,loc2-loc1)
   UserID =NULL

// extract Password
loc1 = index(cmdline,"/P")
if loc1 >0 then
   // find where argument ends (at aspace)
   loc2 = index(cmdline,"",loc1)
   if (loc2 = 0) then
      loc2 =length(cmdline) + 1
   loc1 = loc1+2
   // get thepassword
   PassWord =substring(cmdline,loc1,loc2-loc1)
   PassWord =NULL

The users can pass in the arguments by adding them to the shortcut usedto invoke the application (e.g. if the build application is Loan.exe, theshortcut might be something like "c:\apps\loan.exe /Uscott /Ptiger").

You can test passing the arguments when runningthe application interpretively by either:

  • specifying the arguments in the Command Linewindow of the File.Settings Run tab in the Aion IDE or
  • setting up a shortcut to run reexec.exe with the application nameand the command line arguments (e.g. d:\platinum\aion81\reexecc:\apps\ /Uscott /Ptiger")

Please also note, that the command line is passed to EVERY library thathas a _TaskInitialize defiend in its entry class, not just to theapplication library. For example, if you have Loan.App which, you can check one of the classes in LoanRule.App to be theEntry class then add an _TaskInitialize method to this class with a stringinput argument and this method (as well as the _TaskInitialize in Loan.AppMain._TaskInitialize) will also recieve the command line input.

More general information on the _TaskInitializemethod
This method is for more than just getting commandline arguments. _TaskInitialize can also be used to do one time"initialization" tasks for a library (as the name so aptly implies).When any Aion library is loaded (whether it's the main application, anincluded library, or a library component of another program), if thereis a _TaskInitialize method in the entry class, it will be executedfirst. 

A common use of _TaskInitialize:
 If youwant to initialize some attributes by reading values from theregistry as the application loads, the _TaskInitialize method is a goodapproach to use. See the _Task._TaskInitialize method in Syslib for anexample. Also, when the application is finished, the_TaskTerminate methods (if they exist) in the entry class of the librarywill be executed. This is a good place to put any last minute or "cleanup" logic (eg. saving settings to the registry).