CGI programming with Sicstus ============================= Writing CGI applications with Sicstus Prolog is relatively easy and there is a good library, Pillow, of predicates to generate and parse HTML and XML and to download URL. Unfortunately, the documentation on how to do it is deficient and the most relevant entry "Interfacing with UNIX" in the Sicstus FAQ: http://www.sics.se/sicstus/docs/latest/html/faq.html/ is misleading. PROBLEMS -------- The first problem in using Sicstus for a CGI is that the Sicstus assumes INTERACTIVE use and prints out prompts and messages which conflict with the proper formatting required by CGI. The FAQ shows how these messages can be filtered out by redirecting STDERR to /dev/null as shown below. It also shows how the script can access command-line arguments. To simplify matters, the Prolog code is "inlined" #!/bin/sh exec sicstus 2> /dev/null -f -a "$@" < /dev/null -f -a "$@" < /dev/null -r s1.sav Here is the Prolog program "s1.pl". The last line eases the compilation. main:- prolog_flag(argv, Args), write(Args), nl, read_line(L), write(L), nl, halt. :- save_program(s1,main), halt. Here is how to compile and execute: vor% sicstus -l s1 % compiling /u/vaucher/s1.pl... % /u/vaucher/s1.sav created in 10 msec % compiled /u/vaucher/s1.pl in module user, 20 msec 472 bytes vor% s2 a f b3333 [] <---- S2 doesn't transmit arguments fred <---- this is the line we type in [102,114,101,100] vor% CGI === The same principles were applied to a real CGI application that is given as an example of PILLOW programming: "phones.pl" . You can check out various files in my WWW2 directory http://www2.iro.umontreal.ca/~vaucher/sicstus/ The relevant script is "phones.cgi" whose code you can check via the ALIAS "phones_cgi". It uses the saved state "phones.sav" of "phones.pl" There is another example involving the form "f1.html" which calls the script "debug.cgi" either with the POST or the GET method. Pillow URL: http://clip.dia.fi.upm.es/Software/pillow/pillow.html