docs.roxen.comBack to normal mode
DocsRoxenWebServer 5.4System Developer Manual PikeProgramming Languages
Copyright  2018, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com

CGI I/O Via Standard Streams

The workings of the script's standard streams; stdin, stdout and stderr.

Stdin - Standard Input

Request methods such as HTTP POST and PUT have attached information in the request body that, unlike the common script parameters, is not present as environment variables. This information, CONTENT_LENGTH bytes in total, is instead available for reading from stdin. See also the pervious page (CGI Environment Variables) on environment variables.

Stdout - Standard Output

It is up to your script to write out whatever HTTP response headers it needs to stdout. After the headers (possibly none), the script must produce two newlines, and whatever is written after that ends up in the request body as the webpage seen by the client.

Stderr - Standard Error

Basically, your CGI script talks to the world through stdout and to the logs via stderr. By default, stderr is sent to the main server log, but this may be altered by the server administrator. Your debug and/or logging messages should typically end up on stderr. When your roxen process was started with the --once flag, all stderr output ends up in the console from which Roxen was started.

An example script in /bin/sh exemplifying all of the above might look like this:

#!/bin/sh

if [ -z "$CONTENT_LENGTH" ]; then

cat << end_form
Content-type: text/html

<form method=post>
 <input type=text name=variable size=40
  value="Press submit to see a POST request body.">
 <input type=submit>
</form>
end_form

else

cat << end_reply
Content-type: text/plain

$CONTENT_LENGTH bytes of data were sent to us.
The content-type was $CONTENT_TYPE:

end_reply
cat

fi

echo "CGI example ran at `date`." 1>&2