Command line parameters and environment variables
From Free Pascal wiki
Jump to navigationJump to searchOverview
When a program is started a user can give command line parameters and setup environment variables. For example the FreePascal compiler gets most of its parameters via command line options:
fpc -Fudirectory -gh unit1.pas
Command line parameters
A pascal program can get access the parameters via ParamStr and ParamCount. ParamStr(0) is the program path itself. ParamStr(1) is the first parameter. ParamCount is the number of parameters.
<DELPHI> program Project1;
{$mode objfpc}{$H+}
var
i: Integer;
begin
writeln('Program: ',ParamStr(0)); for i:=1 to ParamCount do writeln('Param ',i,': ',ParamStr(i));
end. </DELPHI>
For example:
$ /tmp/project1 -a Program: /tmp/project1 Param 1: -a