我在 linux 上有一个非常简单的 CGI python 服务器,代码如下:
#!/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()
在同一目录中,我有一个名为 example-bash.sh 的脚本。当我导航到 localhost:8000/example-bash.sh 时,我想要做的只是能够在浏览器中显示该 bash 脚本的输出。当我尝试时,它只是打开文件而不是运行它。
example-bash 仅包含以下代码:
#!/bin/bash
echo "Content-type: text/html"
echo ''
echo 'CGI Bash Example'
我怎样才能让它运行呢?
最佳答案
关于python - 如何从简单的 CGI python 服务器运行 shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27209719/