[Tutor] Testing CGI scripts offline

Kalle Svensson kalle@gnupung.net
Thu, 18 Jan 2001 00:13:49 +0100

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Sez Sean 'Shaleh' Perry:
> On 16-Jan-2001 Jack Green wrote:
> > Hi Guys,
> >=20
> > Just wondering if theres any way i can use my home PC to test my CGI py=
> > scripts, I'm sure theres a way to do it but i cant find one..
> >=20

I'm just going to expand on these:

> a) many cgi can be run from a prompt, if given the right info

One way (The Way, most likely) to ensure a script is given the right info is
setting the correct environment variables.  One to test is QUERY_STRING.
The value of QUERY_STRING is parsed for HTTP GET requests to CGI scripts,
and the standard library module cgi understands it.  The format is simple:

Thus, in a DOS shell (or whatever it's called in NT):
c:\myscripts> set QUERY_STRING=3D"test_input=3Dfoo&checkbox1=3Dfish"
c:\myscripts> python myformparse.py
Content-type: text/html

<title>Test cgi</title>
The value of the input field test_input is: "foo"<br>
The checkbox checkbox1 with value "fish" was checked.<br>

Of course assuming your cgi script generates such an output on that input.
I hope you get the general idea.

If you're on a UNIX machine, the commands are pretty much the same, a bit
depending on your shell.  On a Mac, I have no idea.

> b) install a web server locally.

Personal Web Server for Windows comes "free" with Windows 9x, but might be
tricky to find and I don't know how it handles CGI.  Apache is available
both for Windows and UNIX.  There are others.

Good luck!

Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org