Python Forum

Full Version: Basic python print script output on CGI?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm currently doing some testing if possible to build like a webserver that print outs the result from a script that was based from CLI?

I have run this command, but when I click the script it just show the source code but did not run the script. Anyone here tried building a simple script like ping from shell then print output from CGI(Web),=..

Currently using the default python v2.6 on our linux server and I have no privilledge to download new module etc since my account is not sudoer so I have to stick on whats avilable right now... Is this possible?

Any document for this? Should I build first a html code the call the python script? should I use .py or .exe. thats the common thing that I observe... tho still searching how to build a basic script for cgi.

Tried using this as sample, but after input from webtest.htm once I click the submit it just print the source code of

<form method="get" action="/draft/cgi-bin/">
Name: <input type="text" name="name">
<input type="submit" value="Submit">
#!/usr/bin/env python
import cgi
form = cgi.FieldStorage() 
name = form.getfirst("name")

print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<body>"
print '<h1>Hello ' + name + '! This is a test!</h1><br />'
print '</body>'
print '</html>'
Did you make executable?

chmod a+x
(Jul-28-2019, 02:12 AM)metulburr Wrote: [ -> ]Did you make executable?

chmod a+x

lab@ubuntu:~/Desktop/cgi-bin$ ls -l | grep hel
-rwxr-xr-x 1 lab lab 250 Jul 27 19:40

Tried that man, but still it only show the source code not the output. thanks
I suppose the problem is likely that the web server isn't configured correctly to serve these CGI scripts? Have you checked, or asked the relevant people (whoever the admin is)?
Have you done the steps here to setup the server to correctly serve CGI scripts?