Subject: Re: [SWIPL] HELP-Calling prolog from CGI scripts

From: Jan Wielemaker <[email-masked]>
Date: Wed, 11 Jul 2001 13:02:56 +0200

> 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