Snippet. Vala. How to Read the Arguments Passed to the Program

For most of the console based applications passing arguments at the command line is a convenient way to make the application do some specific action. For instance, print a help screen or execute a non-default option. This snippet demonstrates how to read the arguments passed to a Vala program.

int main (string[] argv) {
    foreach (string arg in argv) {
        stdout.printf ("Argument: %s", arg);
    }
    return (0);
}

Updated on: 23 Nov 2024