Expand/Shrink

command_line

Definition: sequence res = command_line()
Description: Returns a sequence of strings, where each string is a word from the command-line that started your program.
The first word will be the path to either the Phix executable (p.exe, pw.exe, or p), or to your executable file, or "p2js".
The next word is either the name of your Phix main source/htm file, or (again) the path to your executable file.
After that will come any extra words typed by the user. You can use these words in your program.
pwa/p2js: Supported, after a fashion, see technicalia.
Comments: The Phix interpreter itself uses very few command-line options, which must occur before the main source file.
Options after the main source file can be used by your own program.

The user can put quotes around a series of words to make them into a single argument.

If you compile your program you will find that all command-line arguments remain the same, except for the first two, even though your user no longer types "p" on the command-line (see examples below).

In the special case of "p p test" (and "p p p test" etc) command_line() returns the same results as "p test", since doing otherwise would just hamper testing, cause general confusion, and gain nothing.
Example 1:
-- The user types:  p myprog myfile.dat 12345 "The end"
cmd = command_line()
-- cmd will be:
      {`C:\Program Files (x86)\Phix\p.exe`,
       `C:\Projects\myprog\myprog.exw`,
       `myfile.dat`,
       `12345`,
       `The end`}
-- Note the capitalisation of myprog[.exw] may reflect 
-- reality, whereas myfile would always be "as typed".
Example 2:
-- Your program is compiled with the name "myprog.exe"
-- and is stored in the directory C:\MyFiles\.
-- The user types:  myprog myfile.dat 12345 "The end"
cmd = command_line()
-- cmd will be:
       {`C:\MyFiles\myprog.exe`,
        `C:\MyFiles\myprog.exe`, -- (spacer)
        `myfile.dat`,
        `12345`,
        `The end`
        }
-- Note that all arguments remain the same as example 1
-- except for the first two. The second argument is always
-- the same as the first and is inserted to keep the numbering
-- of the subsequent arguments the same, whether your program
-- is compiled to an executable .exe file or not.
Example 3:
string cl2 = command_line()[2]
?get_file_name(cl2) -- eg "test.exw" or "test.exe" or "test.htm"
Implementation: See builtins\VM\pcmdlnN.e (an autoinclude), and/or pwa\p2js.js (ie core), for details of the actual implementation.
See Also: getenv, get_interpreter
Expand/Shrink