Python Forum
Basic python print script output on CGI?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic python print script output on CGI?
#1
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 hello.py.

webtest.htm
<html><body>
<form method="get" action="/draft/cgi-bin/hello.py">
Name: <input type="text" name="name">
<input type="submit" value="Submit">
</form>
</body></html>
hello.py
#!/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>'
Reply
#2
Did you make hello.py executable?
https://python-forum.io/Thread-Run-Pytho...rom-Apache

chmod a+x hello.py
Recommended Tutorials:
Reply
#3
(Jul-28-2019, 02:12 AM)metulburr Wrote: Did you make hello.py executable?
https://python-forum.io/Thread-Run-Pytho...rom-Apache

chmod a+x hello.py

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

Tried that man, but still it only show the source code not the output. thanks
Reply
#4
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)?
Reply
#5
Have you done the steps here to setup the server to correctly serve CGI scripts?
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with understanding basic IP script mickandralphscrier 6 3,448 Nov-04-2018, 02:37 PM
Last Post: mickandralphscrier

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020