HTTP server

Simon Forman rogue_pedro at yahoo.com
Sat Jun 24 11:25:32 EDT 2006


placid wrote:
> Hi all,
>
> Ive been reading about creating a HTTP server like the one pydoc
> creates (and studying pydoc source code). What i want to know, is it
> possible to create server that creates a webpage with hyperlinks that
> communicate back to the HTTP server, where each link accessed tells the
> server to execute some arbitrary command on local machine its running
> on?
>
> Cheers

Yes.   It is possible.


Ok, seriously,  I don't know how pydoc does it, but when I need a
quick-and-dirty http server [written in python] I use something like
this:

from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

HTTPServer(('', 8000), SimpleHTTPRequestHandler).serve_forever()

For what you're asking about you'd probably want to use the
CGIHTTPRequestHandler from the CGIHTTPServer module instead.  Check out
http://docs.python.org/lib/module-CGIHTTPServer.html

Then you'd just write one or more cgi scripts (they can be in python
IIRC) to run the commands you want.

HTH,
~Simon




More information about the Python-list mailing list