Command-line argument parsing

This is an old revision of this page, as edited by 212.4.138.50 (talk) at 14:44, 3 June 2010 (Python). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Different Command-line argument parsing methods are used by different programming languages to parse command-line arguments.

Programming languages

C

C uses argv to process command-line arguments.[1]

Java

An example of Java argument parsing would be:

public class Echo {
    public static void main (String[] args) {
        for (String s: args) {
            System.out.println(s);
        }
    }
}

Perl

Perl uses $ARGV.

PHP

PHP uses argc as a count of arguments and argv as an array containing the values of the arguments.[2][3] For example:

var_dump($argv);

Python

Python uses sys.argv, e.g.:

for arg in sys.argv:
  print arg

References

  1. ^ "The C Book — Arguments to main". Publications.gbdirect.co.uk. Retrieved 2010-05-31.
  2. ^ "PHP Manual". PHP. Retrieved 2010-05-31.
  3. ^ wikibooks:PHP Programming/CLI