1

Say I have a web page like this on an Ubuntu 12.04 web server running apache:

<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
  http-equiv="content-type">
  <title>Name Input</title>
</head>
  <body>
    <form action="./test.py" method="post"> 
      <p> Name: <input type="text" name="name" id="name" value=""/></p> 
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>

I want to use the value of name as input to a shell script which is called by a Python CGI script like this.

test.py:

#!/usr/bin/env python
import commands, cgi, cgitb
form = cgi.FieldStorage() 
name = form.getvalue('name') 
result = commands.getoutput("/usr/lib/cgi-bin/test.sh name")
contents = pageTemplate.format(**locals())
print "Content-type: text/html\n\n"
print contents

In the example code above, how should name be passed to test.sh?

For completeness, say that pageTemplate looks like this:

pageTemplate = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
  http-equiv="content-type">
  <title>Name Output</title>
</head>
  <body>
    {result}
  </body>
</html>
'''

1 Answer 1

1

Just pass it into the command:

result = commands.getoutput("/usr/lib/cgi-bin/test.sh %s" % name)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.