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

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

On Wed, 11 Jul 2001, Jacobo Myerston wrote:
>I've inserted the line:
>
>>
>>#!/usr/local/bin/pl -q -g main -s
>
>in cgidemo.pl
>
>>but, I got only three characters in the browser: 1 ?- 

cgidemo.pl was written well before 4.0.5.  I've updated it a bit,
and the following behaves nicely on the query

http://<host>/cgi-bin/cgidemp.pl?hello=world

===================================================================
#!/usr/bin/pl -q -g main -s
/*  $Id: cgidemo.pl,v 1.3 2001/07/11 18:09:43 jan Exp $

    Part of SWI-Prolog
    Designed and implemented by Jan Wielemaker

    Copyright (C) 1999 SWI, University of Amseterdam. All rights reserved.
*/

:- use_module(library(cgi)).

main :-
	cgi_get_form(Arguments),
	format('Content-type: text/html~n~n', []),
	format('<HTML>~n', []),
	format('<HEAD>~n', []),
	format('<TITLE>Simple SWI-Prolog CGI script output</TITLE>~n', []),
	format('</HEAD>~n~n', []),
	format('<BODY>~n', []),
	format('<H1>Form arguments</H1>'),
	format('<P>', []),
	print_args(Arguments),
	format('<BODY>~n</HTML>~n', []),
	halt.

print_args([]).
print_args([A0|T]) :-
	A0 =.. [Name, Value],
	format('<B>~w</B>=<EM>~w</EM><BR>~n', [Name, Value]),
	print_args(T).
=====================================================================

To install it under Unix, simply put this as an executable file in the
CGI-Bin directory.  Make sure the path after #! is correct.  Note the
call to halt/0 to make the CGI script end.

	--- Jan