python - 如何从简单的 CGI python 服务器运行 shell 脚本?

标签 python linux bash shell

我在 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'

我怎样才能让它运行呢?

最佳答案

确保 shell 脚本是可执行的。

chmod +x example-bash.sh

DEMO

关于python - 如何从简单的 CGI python 服务器运行 shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27209719/

相关文章:

python - STATIC_ROOT 和 MEDIA_ROOT 正确配置

python - 使用 xlsxwriter 在条件格式(公式)后删除列

mysql - 从 bash 脚本查询 mysql

linux - 使用 bash 脚本从文件中删除字符串

Python 的 subprocess.Popen() 结果与命令行不同?

python - 使用 python 将文本文件加载到数据库中

python - 查找句子中的字典值并输出句子、键

linux - 如何在测试期间模拟故障磁盘?

c++ - 读取/dev/ttyACM0 文件的速度有多快?

java - 从 CentOS 7 终端调用 java 程序