; ; @ANO_SCRIPT_NAME cmdline_input ; @ANO_SCRIPT_VERSION 0.0.1 ; @ANO_SCRIPT_DESCRIPTION Example how to read input from command line ; ; @ANO_FLAGS_VAR_NAME_SUBS [ ] ; @ANO_FLAGS_VAR_WARN_UNUSED [ ] ; ; Copyright (c) 2016-2025, Jani Salonen ; All rights reserved. ; ; This example reads input from command line. ; ; Possible ways to get the input is listed below. General syntax for command ; line is: ; ; $ application --engine-param1 --engine-param2 \ ; FILE1 param1_for_file1 FILE2 param1_for_file2 param2_for_file2 ... ; $ application -- param1 param2 ... ; ; First example reads input and dumps it out: ; ; $ ./cmdline_input ; XXX ; rc is string (UTF-8) "XXX" ; There are 0 options in command line. ; There are 0 files provided in command line. ; ; Read input through pipe: ; ; $ echo XXX | ./cmdline_input ; rc is string (UTF-8) "XXX" ; There are 0 options in command line. ; There are 0 files provided in command line. ; ; Read input, get existing file name and three parameters for it: ; ; $ echo XXX | ./cmdline_input cmdline_input 1 2 3 ; rc is string (UTF-8) "XXX" ; There are 0 options in command line. ; There are 1 files provided in command line. ; file 0 is cmdline_input. ; there are 3 parameters for cmdline_input. ; parameter 0 is 1. ; parameter 1 is 2. ; parameter 2 is 3. ; ; Read input, use engine parameter and four plain parameters for this script: ; ; $ echo XXX | ./cmdline_input -du -- nonexistent 1 2 3 ; rc is string (UTF-8) "XXX" ; There are 0 options in command line. ; There are 1 files provided in command line. ; file 0 is cmdline_input. ; there are 4 parameters for cmdline_input. ; parameter 0 is nonexistent. ; parameter 1 is 1. ; parameter 2 is 2. ; parameter 3 is 3. ; ; Application parameters can be read too, if they are defined in ; work/cmdline_app.h: ; ; $ ./cmdline_input --my_parameter ; main [exit: 0] { ; Read from stdin and dump it out ; input_read (mode: INPUT_TERM_CRLF) dump rc ; Get amount of app specific options in command line ; _args = cmdline_get_args print "There are " . _args . " options in command line.\n" for (mov _i (0); _i < _args; inc _i) { ; Get option short name by index ; _short = cmdline_get_arg (arg_index: _i) print " option " . _i . " short name is " . _short . ".\n" ; Get option long name by index ; _long = cmdline_get_arg_long (arg_index: _i) print " option " . _i . " long name is " . _long . ".\n" ; Get option value by index skipping secure options ; _value = cmdline_get_arg_by_index (arg_index: _i) print " option value is " . _value . ".\n" ; Get option value by arg short or long name skipping ; secure options ; _value = cmdline_get_arg_by_name (arg_name: _short) print "\n" } ; Get amount of files provided in command line, files are existing ; files not attached to any keyword ; _files = cmdline_get_files print "There are " . _files . " files provided in command line.\n" for (mov _i (0); _i < _files; inc _i) { ; Get file name by index ; _file = cmdline_get_file (file_index: _i) print " file " . _i . " is " . _file . ".\n" ; Get amount of params for file by index ; _args = cmdline_get_file_args (file_index: _i) print " there are " . _args . " parameters for " . _file . ".\n" for (mov _j (0); _j < _args; inc _j) { ; Get file param by file index and parameter index ; _arg = cmdline_get_file_arg (\ file_index: _i, \ arg_index: _j) print " parameter " . _j . " is " . _arg . ".\n" } print "\n" } }