Command-line Arguments

Top  Previous  Next

The server allows you to specify a command line to be passed to the application it invokes, for use as program arguments. These arguments are passed to every task that has been linked against the full Diamond library; stand-alone tasks are not passed arguments.

 

By clicking View, then Options, and then selecting the General tab, you bring up a window that allows you to give your command line arguments. The arguments are remembered by the server and are used each time you run the server until you change them.

 

The command line is broken into program arguments, and these are made available to the tasks in an application in the usual C way. When the C main function is called, it is passed the following parameters  (as well as others):

 

int main(int argc, char *argv[])

 


argv

is a vector of pointers to the arguments, each of which is a zero-terminated string.


argv[0]

points to the name of the application that is running. It is NULL if the task is stand-alone.


argv[n]

points to the nth command-line argument;


argc

is the number of arguments, including the program name. It is always at least 1; it is always 1 for stand-alone tasks.


argv[argc]

is always a null pointer.

 

In fact, the main function has more parameters than these. The others are used for inter-task communications and are discussed in Inter-Task Communication.

 

Consider executing the command 3L X myprog having previously set the following:

 

CommandLine

 

The server starts the application myprog.app and passes in the following values

 

argc

will be 2

argv[0]

will point to the string "myprog.app",

argv[1]

will point to the string "Simplicity"

argv[2]

will be a NULL pointer.