Microsoft KB Archive/65923

= Interrupt to Get QB/QBX Invocation Command Line; vs. COMMAND$ =

Article ID: 65923

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b

-



This article was previously published under Q65923



SUMMARY
Below is an example of how to do a DOS interrupt to obtain the command-line arguments used to invoked a QuickBasic program. The sample program works in the QB.EXE/QBX.EXE environment and in an .EXE program. This program can be used to obtain the name of the Quick library that QB or QBX was invoked with.

The program returns the complete command line entered (if any) after your .EXE or QB/QBX program name. The Basic language offers the COMMAND$ function to do the same thing, but COMMAND$ returns nothing in the QB.EXE/QBX.EXE environment.

This sample code applies to Microsoft QuickBasic versions 4.00, 4.00b, and 4.50; to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS; and to Microsoft Basic PDS versions 7.00 and 7.10 for MS-DOS. (The code will also run under the DOS 3.x box in MS OS/2's real mode, but will not run under MS OS/2's protected mode.)



MORE INFORMATION
The following program uses DOS interrupt 21 hex, with function 62 hex, to find the segment address of the program segment prefix (PSP). Based on this information, the program then uses the PEEK function to read the command line from memory. The Arguments$ function in the example returns a string containing all command-line arguments.

The program arguments are located at an offset of &H80 (80 hex) from the PSP. The first byte at this offset is the number of characters in the command tail, followed by a string of ASCII characters terminated by a carriage return; the carriage return is not included in the count.

For more information about MS-DOS interrupts, please refer to the following excellent book:

&quot;Advanced MS-DOS Programming, Second Edition&quot;, by Ray Duncan, published by Microsoft Press (1988).

Sample Code
To use this sample code, QuickBasic must be started with the /L option to load the default Quick library, QB.QLB or QBX.QLB, which contains the necessary INTERRUPT routine. (In QuickBasic 4.x or Basic compiler 6.00x, the default Quick library is QB.QLB; in Basic PDS 7.00 and 7.10, it is QBX.QLB). Name the following program TEST.BAS: ' $INCLUDE: 'qb.bi' ' In QuickBasic 4.x or Basic compiler 6.00x, use the above include; ' but in Basic PDS 7.00 and 7.10, change the above to use 'QBX.BI'

DECLARE FUNCTION Arguments$

args$ = Arguments$ PRINT args$ END

FUNCTION Arguments$

DIM regs AS RegType regs.ax = &H6200 CALL INTERRUPT(&H21, regs, regs)  ' Get the address of the PSP DEF SEG = regs.bx                 ' Set the current segment count = PEEK(&H80)                ' Get the number of characters a$ = &quot;&quot; FOR a = 2 TO count                ' Read the arguments from memory

a$ = a$ + CHR$(PEEK(&H80 + a))

NEXT Arguments$ = a$                   ' Return the arguments to program END FUNCTION If you invoked this program with QB TEST/L QB.QLB or QBX TEST/L QBX.QLB the program will print the following:   TEST/L QB.QLB or   TEST/L QBX.QLB If you invoked this program from an .EXE program (such as TEST.EXE) as follows TEST ARG1 ARG2 then the program will print the following:   ARG1 ARG2

Additional query words: QuickBas BasicCom

Keywords: KB65923

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.