Microsoft KB Archive/60869

{|
 * width="100%"|

Referring to the Command-Line Tail

 * }

Q60869

-

The information in this article applies to:


 * Microsoft C for MS-DOS, versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 1.5

-

SUMMARY
The following code example demonstrates how an application can explicitly reference the command-line tail. The example accesses the Disk Transfer Area (DTA) to refer to the entire command line with spaces intact and prints the command line as one string.

In this method, the command line is limited to 128 bytes. If this code example is compiled as CMDLINE.EXE and invoked with the following command line

  cmdline *.c  abc  def  lab7.pas the program produces the following output:

  tail_length = 24 cmd_tail = &lt; *.c abc  def  lab7.pas&gt; NOTE: A more portable method to retrieve this information is to use the argv and argc parameters for the main function. The output from this method may be easier to use because setargv function partially parses the command line.

Sample Code
/* * Compile options needed: none */


 * 1) include 
 * 2) include 

main {  int tail_length; char cmd_tail[128]; char far *p;            /* far pointer */ int i;

struct SREGS Seg; union REGS Reg;

Reg.h.ah = 0x2F;        /* DOS call:  Get DTA Address   */ segread(&Seg); intdosx(&Reg, &Reg, &Seg);

FP_SEG(p) = Seg.es;     /* make p point to the DTA */ FP_OFF(p) = Reg.x.bx;

tail_length = *p;       /* First byte is length of tail string */

printf(&quot;tail_length = %d\n&quot;, tail_length);

p++;                    /* Move to first byte */

for(i = 0; i < tail_length; i++) cmd_tail[i] = p[i];

cmd_tail[tail_length] = '\0'; /* Add NULL to make a string */ printf(&quot;cmd_tail = <%s>\n&quot;, cmd_tail);

return(0); } Additional query words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbZNotKeyword3 kbCVC700DOS