5

I have a very simple CGI python server on linux with the following code:

#!/usr/bin/env python

import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable()  ## This line enables CGI error reporting

server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = ["/"]

httpd = server(server_address, handler)
httpd.serve_forever()

In the same directory, I have a script named example-bash.sh. What I want to do is simply be able to display the output of that bash script in the browser when I navigate to localhost:8000/example-bash.sh. When I try, it just opens the file instead of running it.

example-bash simply has the following code:

#!/bin/bash
echo "Content-type: text/html"
echo ''
echo 'CGI Bash Example'

How can I make it run instead?

1 Answer 1

3

Make sure that the shell script is executable.

chmod +x example-bash.sh

DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

Didn't work for me through firefox. It probably worked for you because you're already in the cmd line.
@user2997154, It works for me in browser, too (chrome, firefox).
I downloaded chrome and it worked in there, thanks. Still doesn't work in firefox though. Not sure why

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.