Enviroment variables_(re)
Thu, 14 Aug 1997 23:04:17 +-200
Hello!
According to Fred:
> I'd like to use GPC for some simple CGIs I'm writing for my own server.
>
>To accomplish this I need to know how to:
>
>1) Read from various environment variables like $QUERY_STRING.
>2) Read from Standard Input.
>
>Any and all help greatly appreciated.
>
Here's a litte demo program (i learn best with demo programs :-).
It declares the "getenv" function itself and doesn't need any other unit.
But there is a "bpcompat" unit for that and a lot of other useful things.
{$x+} (* <- Enable extended syntax *)
PROGRAM cgi1(Input, Output);
TYPE
tStr255 = String(255);
FUNCTION GetEnv(Name : pChar):pChar; C;
(* get access to the getenv funktion in c rtl *)
VAR
St : tStr255;
BEGIN
(* write some environment variables *)
WriteLn(' TERM : ', GetEnv('TERM'));
WriteLn(' SHELL: ', GetEnv('SHELL'));
(* now echo all stdin *)
WHILE NOT Eof(Input) DO BEGIN
ReadLn(Input, St);
WriteLn('>>', St);
END;
END.
Hope this helps,
Achim
Achim Kalwa (achim.kalwa@do.netsurf.de)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es