COMMAND$ function

Purpose: COMMAND$ returns the command line tail, that is, a character string containing everything typed on the command line after the filename that started the program.


 Syntax 1:

 RetStr$ = COMMAND$

 Parameters:

  • None.

 Return Value:

  • RetStr$, the return string, contains everything typed on the command line after the filename that started the program.

Example:


 DIM RetStr$
 RetStr$ = COMMAND$
 PRINT RetStr$


 Syntax 2:

 RetStr$ = COMMAND$(ArgCount%)

 Parameters:

  • ArgCount% Integer representing position of the argument returned in RetStr$ in the command line string. This value is zero based. COMMAND$(0) will return the name of the executable which started the program.

 Return Value:

  • RetStr$, the return value, is a string containing the argument at the ArgCount% position of the command line string.

Example: This example uses the BCX translator internally generated 'argc' parameter of the C 'main' function. 'argc' contains the number of arguments on the command line of the executed program.


 DIM cmd$
 DIM i%, tailargs%
  
 cmd$ = COMMAND$
 tailargs% = argc - 1
  
 PRINT "Full command tail: [", cmd$, "]"
 PRINT "The executable name is [", COMMAND$(0), "]"
  
 FOR i% = 1 TO tailargs%
   cmd$ = COMMAND$(i)
   PRINT "Argument", i, " is [", cmd$, "]"
 NEXT i%
  
 PRINT "Total command tail arguments:", tailargs%

Using COMMAND$ to detect drag and dropped files

COMMAND$ is drag and drop aware and can capture the path and name of a file that is drag and dropped or copied and pasted on to its executable.

The following example will capture the path\filename of any file dropped on it and show a Message Box with, and print to a file, the path\filename of the dropped file.


 DIM Filename$
 DIM A$

 'Use this to write to Current folder
 'Filename$ = CurDir$ &"\TestFile.txt"
 'Use this to write to exe folder
 Filename$ = APPEXEPATH$ &"TestFile.txt"

 OPEN Filename$ FOR APPEND AS FP1
 A$ = COMMAND$
 MSGBOX A$
 FPRINT FP1, A$
 CLOSE FP1

BCX Console Sample Programs using statement function.

S06.bas, S44.bas, S47.bas, S48.bas, S64.bas, S65.bas, S67.bas, S68.bas, S71.bas, S73.bas, S74.bas, S77.bas, S96.bas, S98.bas, S103.bas, S105.bas, S141.bas,