I have a simple CGI program that accepts data from a form does stuff with it. Of course it crashes the first time, and the server error message is not helpful. It is run by means of the line at the front: #!c:/rebol-sdk/tools/rebcmd.r -cs A CGI program can be run from the REBOL console, but the input form is not available with that approach. What I want to do is put code in the program that says, in effect: IF I was started by a web browser THEN accept data from the html form ELSE ask for the data items from the console This would allow me to run the script "off-line" so to speak and see the error messages. The question is, is there something available in REBOL that I can use to detect if the program was run through the console or through CGI? Thank you.
See http://www.rebol.com/docs/apache-cgi.html on how to setup the first line in your CGI script. Read http://www.rebol.com/docs/cgi2.html and see Seeing All the CGI Data
either system/options/cgi/remote-addr [ RUN-AS-CGI: true ] [ RUN-AS-CGI: false ] Thank you. Works like a charm.
Now that is interesting. If I did not finally know that 1) remote-addr is the address of the calling computer, 2) that remote-addr has a value of "none" if there is no calling computer, 3) that a value of "none" returns "false" in a test with the "if" function, and 4) that a non-none value returns a value of "true" in an "if" test, I would find your line of code hard to understand. That might explain, partly, why I did (and sometimes still do) find REBOL hard to understand. Also, it seems that your one line is a "REBOL-ish" way of coding, whereas mine is a more "COBOL-ish" way. That suggests to me that the tools we are used to using can influence our thinking, and sometimes trap us in certain ways of thinking.
Well, if you know what are truth values, then you can do the assignment directly rather than testing twice. This is just a form of code factoring.