Purpose |
Return the command-line used to start the program. |
Syntax |
s$ = COMMAND$ |
Remarks |
COMMAND$ returns everything that was typed following the program name. Some operating system manuals refer to this text as the trailer or command tail. Use COMMAND$ to collect run-time arguments, like filenames, and program options. For example, consider a program named FASTSORT.EXE that reads data from one file, sorts it, and puts the result in a new file. Using COMMAND$ lets you specify the input and output file names when the program is invoked: FASTSORT.EXE cust.dta cust.new When FASTSORT begins execution, COMMAND$ will hold
the
cust.dta cust.new FASTSORT must include code to parse this string into two file names. |
Restrictions |
In some recent versions of Windows, file association and drag-drop file operations cause filenames to be enclosed with double-quote marks when they are passed in COMMAND$. It would be wise to ensure that your applications are prepared for this possibility. Some operating systems automatically enclose the command-line in double-quote marks. PowerBASIC imposes no arbitrary limits on the length of the string returned by COMMAND$ but, the operating system may impose limits. Such limits may become evident, for example, when attempting to Drag and Drop a large number of files onto an EXE within Windows Explorer. Usually, attempting to drop more files than the operating system permits will result in an operating system warning message. Within the IDE, a COMMAND$ command-line parameter can be specified for the purposes of testing in both Compile and Execute and Compile and Debug modes. |
See also |
|
Example |
#COMPILE EXE FUNCTION PBMAIN IF TRIM$(COMMAND$) = "" THEN EXIT FUNCTION ' No command-line params given, just quit ELSEIF INSTR(COMMAND$, "/Q") THEN ' Process the /Q option ELSEIF INSTR(COMMAND$, "/W") THEN ' Process the /W option END IF END FUNCTION |