'=========================================================================== ' Subject: COMMAND LINE UNDER MSDOS 7 Date: 02-21-97 (21:32) ' Author: Hans Lunsing Code: QB, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: DOS.ABC '=========================================================================== 'Under MSDOS 7, the DOS version coming with Windows 95, the command line 'can be much longer than under older versions, that is 1024 bytes. As a 'consequence the command tail (the command line arguments) can be much 'longer than the older maximum of 126 bytes. QB's COMMAND$ function 'doesn't accomodate this long command tails but truncates them. So I 'made a replacement for COMMAND$, which gets the command tail from the 'newly introduced environment variable CMDLINE if that variable exists. 'Otherwise it gets the command line from the PSP, the Program Segment 'Prefix. In both cases case is preserved, contrary to what COMMAND$ 'does. 4DOS (version 5.5 at all events) also has the environment 'variable CMDLINE, but under older versions of DOS the maximum length of 'the tail remains 126. ' CmdTail.Bas ' Freeware by Hans Lunsing (c) 1997 ' e-mail jlunsing@doge.nl '----------------------------------------------------------------------- DEFINT A-Z '$INCLUDE: 'qb.bi' DECLARE FUNCTION CmdTail$ () DECLARE FUNCTION PeekString$ (Offset AS INTEGER, Length AS INTEGER) FUNCTION CmdTail$ ' ---------------------------------------------------------------------- ' Replacement for COMMAND$. ' Gets command line arguments for basic program, preserving case and the ' longer possible length under MSDOS 7 (Windows 95) and under older ' versions of DOS when using 4DOS 5.5 (and maybe older versions). ' Note that in the IDE this function returns the command tail for the IDE, ' including the command tail for the program preceded by /cmd, if given, ' but not the command tail for the program as given via the Run - ' Modify COMMAND$ menu choice. ' ---------------------------------------------------------------------- DIM CmdLine AS STRING DIM Reg AS RegType DIM Separator AS INTEGER DIM Space AS INTEGER DIM Switch AS INTEGER 'First try to get command line from environment variable CMDLINE CmdLine$ = ENVIRON$("CMDLINE") IF LEN(CmdLine$) THEN Space = INSTR(CmdLine$, " ") Switch = INSTR(CmdLine$, "/") IF Space + Switch = 0 THEN 'No command line arguments CmdTail$ = "" ELSE 'Get command line arguments IF Space < Switch THEN Separator = Space ELSE Separator = Switch END IF CmdTail$ = LTRIM$(MID$(CmdLine$, Separator)) END IF ELSE 'If environment variable CMDLINE is empty we get the command line 'tail from the PSP 'First get PSP segment in Reg.bx, and then get command tail from 'offsets &h81 and following in the PSP. The length of the command 'tail is on offset &h80. Reg.ax = &H6200 CALL INTERRUPT(&H21, Reg, Reg) DEF SEG = Reg.bx CmdTail$ = PeekString$(&h81, PEEK(&h80)) END IF END FUNCTION FUNCTION PeekString$ (Offset AS INTEGER, Length AS INTEGER) '----------------------------------------------------------------------- ' Reads a string from memory. ' The memory segment must be set beforehand with the DEF SEG command. '----------------------------------------------------------------------- IF Length > 0 THEN PeekString$ = STRING$(Length, 0) FOR i = 1 TO Length MID$(PeekString$, i, 1) = CHR$(PEEK(Offset - 1 + i)) NEXT i ELSE PeekString$ = "" END IF END FUNCTION