Definition: | sequence s = 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 phix), or to your executable file. The next word is either the name of your phix main source 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. |
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"} |
Example 2: |
-- Your program is bound 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 bound as a .exe or not. |
See Also: | getenv, get_interpreter |