The Turbo Pascal functions
ParamStr and
ParamCount give us access to command line arguments.
ParamCount returns the number of command line arguments while
ParamStr(i : Word) returns the individual parameter strings.
Ekho illustrates the use of these two functions. We use the spelling Ekho instead of Echo to avoid colliding with the DOS command ECHO.
Program Ekho ;
{
echo command line arguments to output.
}
Uses
Tools ;
Var
i : Byte ;
begin
for i := 0 to ParamCount do
Write (ParamStr(i), BLANK) ;
WriteLn
end.
Note that even if no parameters are included on the command line we still get output. ParamStr(0) is the executable file itself. Thus:
c:\pascal\tools\ekho
C:\PASCAL\TOOLS\EKHO.EXE
The next few programs we write will use command line parameters.