From jan@swi.psy.uva.nl Wed Jul 11 13:02:57 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f6BB2vX08481;
	Wed, 11 Jul 2001 13:02:57 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f6BB2uf28820;
	Wed, 11 Jul 2001 13:02:56 +0200
Date: Wed, 11 Jul 2001 13:02:56 +0200
Message-Id: <200107111102.f6BB2uf28820@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [SWIPL] HELP-Calling prolog from CGI scripts
To: prolog@swi.psy.uva.nl, prolog-request@swi.psy.uva.nl
Phone: +31 - 20 - 525 6121

> I am trying to call a prolog patrII grammar parser from a cgi-script. 
> What I want to do is read in a query string from the script and pass it to
> the prolog patr parser and then display the parse tree. Can anyone tell me
> how to connect and call prolog from cgi???
> Millions of thanks in advance

There are various options and three things to take care of.  Some of
these are platform specific.

	1) Make Prolog quiet, so only the desired page is emitted

	2) Ensure the web-server can find your Prolog script

	3) Read the CGI form-data

You can achieve (1) two ways. Use the -q option (only in recent
versions) or make a saved-state using qsave_program.

(2) is platform dependent. You can do (3) many ways. The fat (non-lite)
version defines library(cgi) for this, documented in libc.html.

On Unix, I normally do:

#!/usr/local/bin/pl -q -g main -s

:- use_module(library(cgi)).

main :-
	cgi_get_form(Arguments),	
        format('Content-type: text/html~n~n', []),
	....

On Windows this might work as well provided the script is, using
its extension, connected to plcon.exe.

	Regards --- Jan

