How do I call a python function with parameters in

2019-07-28 06:54发布

问题:

I want to build an interface for browsing an Apache2 server using python scripts.

I spent the past days learning python and today getting familiar with CGI. I want to test out some stuff, like the possibility for the user to navigate to the path he wants from the base directory

/var/www/cgi-bin

by inputting the path he wants to visit, for example

/etc/httpd/conf.d.

For that i have the change_path.py script which looks like this:

import os

def changePath(path):
    os.chdir(path)

I already got this script running to make sure everything is set up properly:

#!/usr/bin/python

# Import modules for CGI handling 
import cgi, cgitb, os 

cwd = os.getcwd()

print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>TestScript</title>"
print "</head>"
print "<body>"
print "<h2> Current working directory is: %s</h2>" % cwd
print "</body>"