INF: How to Explicitly Reference Command-Line Tail

ID Number: Q60869

5.00 5.10 6.00 6.00 6.00ax 7.00

MS-DOS

Summary:

The following code allows you to explicitly reference the command-line

tail. The entire command line with spaces intact is referenced at the

Disk Transfer Area (DTA) address and printed out as one string.

Sample Code

-----------

/* Compile options needed: none

*/

#include <stdio.h>

#include <dos.h>

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 tailstring */

printf("tail_length = %d\n", 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("cmd_tail = <%s>\n", cmd_tail);

return(0);

}

More Information:

Note: The command line is limited to 128 bytes.

cmdline *.c abc def lab7.pas

Output using the above command line is as follows:

tail_length = 24

cmd_tail = < *.c abc def lab7.pas>

Note: A more portable way of getting this information is to use the

argv mechanism built into C. This may be easier because the command

line would be already partially parsed by the setargv() function.

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00