(***********************************************************************) (* *) (* Caml examples *) (* *) (* Pierre Weis *) (* *) (* INRIA Rocquencourt *) (* *) (* Copyright (c) 1994-2011, INRIA *) (* All rights reserved. *) (* *) (* Distributed under the BSD license. *) (* *) (***********************************************************************) (* $Id: argcargv.ml,v 1.5 2011-08-08 19:31:17 weis Exp $ *) (** Prints out the arguments and the number of arguments of a Caml program. Usage: compile this file with the compiler/linker ocamlc, then execute the [a.out] executable program generated by ocamlc. $ ocamlc argcargv.ml Then launch the program with various arguments. For instance, try: $ a.out $ a.out 1 2 $ a.out 1 2 "ok" -f "/tmp/foo" *) open Printf;; let main argc argv = printf "Command line has %i arguments\n" argc; for i = 0 to argc - 1 do printf "argument %i is %s\n" i argv.(i) done ;; main (Array.length Sys.argv) Sys.argv ;;