[comp.os.msdos.programmer] COMMAND LINE RECALLING

UD156844@NDSUVM1.BITNET (06/04/91)

Hi,

I'm interested in writing a program to recall previous parameters
issued on the DOS command line.  My question is where are these
commands placed by DOS.  Are they placed in the PSP?  Next what
type of interrupt is used to fetch the command?  Will I interrupt this
command to relocate it in a table then continue to execute the command?
As you can probably tell I'm an inexperianced DOS programmer, but I
feel this program will help me to learn while not being immpossible
for my level of abilities.  So I would appreciate any suggestions
and help!  By the way I will write this in either C or Assembly.

Thanks in advance!

Roberto Alvarez
UNIVERSITY OF NORTH DAKOTA
UD156844@NDSUVM1
UD156844@VM1.NODAK.EDU

bingham@hpnmdla.sr.hp.com (David Bingham) (06/05/91)

>    I'm interested in writing a program to recall previous parameters
>    issued on the DOS command line.  My question is where are these
>    commands placed by DOS.  Are they placed in the PSP?  Next what
>    type of interrupt is used to fetch the command?  Will I interrupt this
>    command to relocate it in a table then continue to execute the command?
>    As you can probably tell I'm an inexperianced DOS programmer, but I
>    feel this program will help me to learn while not being immpossible
>    for my level of abilities.  So I would appreciate any suggestions
>    and help!  By the way I will write this in either C or Assembly.
>
>    Thanks in advance!
>
>    Roberto Alvarez
>    UNIVERSITY OF NORTH DAKOTA


  DOS (and Unix) pass two arguments into the program, an integer
and a pointer to an array of pointers. The integer (argc) represents
the number of paramaters on the command line. The pointer (argv)
points to each paramater on the command line. Here are two examples:


/* comline.c */
/* demonstrates commandline arguments */
main(argc, argv)
int argc;
char *argv[];
{
	int j;
	printf("Numer of arguments is %d\n", argc);
	for(j=0; j<argc; j++)
		printf("Argument number %2d is %s\n", j, argv[j] );
}

------------------------------------------------

/* comline.c */
/* demonstrates commandline arguments */
main(argc, argv)
int argc;
char *argv[];
{
	int j;
	printf("Numer of arguments is %d\n", argc);
	for(j=0; j<argc; j++)
		printf("Argument number %2d is %s\n", j, *(argv + j) );
}

Both of these examples work with Turbo C as well as an ANSI compiler such
as Unix cc. 
   I hope this helps. If you need, I can scare up these routines in assembler.
I know I've got them somewhere. (I'm not exactly partial to doing most of my
programming in assembler :) )

David
************************************************************************
David Bingham		 	* The power of faith and love 
Hewlett Packard 		* Can change the stuff we're made of
bingham@hpnmqa1.sr.hp.com	*		Michael W. Smith

davet@cbnewsj.att.com (Dave Tutelman) (06/07/91)

In article <11270008@hpnmdla.sr.hp.com> bingham@hpnmdla.sr.hp.com (David Bingham) writes:
Roberto Alvarez (U. of North Dakota) writes:
>>    I'm interested in writing a program to recall previous parameters
>>    issued on the DOS command line.  My question is where are these
>>    commands placed by DOS.  Are they placed in the PSP?  
>>	... [ and other DOS programming questions ] ...

To which David Bingham (bingham@hpnmdla.sr.hp.com) replies:
>
>  DOS (and Unix) pass two arguments into the program, an integer
>and a pointer to an array of pointers. The integer (argc) represents
>the number of paramaters on the command line. The pointer (argv)
>points to each paramater on the command line....

As in jeopardy -- BZZZT!  
Right answer, but wrong question.
That is, David's reply was factual, but had nothing to do with Roberto's
question.  Roberto wanted to know how MSDOS handled command-line arguments,
not how C programmers could handle them.

The answer is, they occupy the last half of the PSP.  A couple of caveats
(perhaps not all the caveats you need to know) about this string, which
is called the command tail:
   -	It does NOT include the program name itself, just what follows.
   -	It does NOT include any redirection information (>, <, |).
   -	There's no padding, compression, or nulling of "blanks".
   -	Byte 128 is the length of the command tail string.  It's not
	necessarily null-terminated, so you need to know length.
   -	Use it and keep results early, because a very few programs may
	also use these 128 bytes as a disk transfer area (DTA).

This information and the answers to Roberto's other questions are available
in several good books.  My favorite for this level is Norton's "Programmer's
Guide to the IBM PC."  There are other excellent books by Ray Duncan and
by the Waite Group.  I recommend you get a few and keep them at hand as
you program.

Hope this helps.
Dave