简体   繁体   English

使用Web服务器上的参数运行python脚本的最简单方法

[英]Easiest way to run python script with parameters on a web server

Thought this would be straightforward, but it's giving me a lot of trouble. 认为这很简单,但它给了我很多麻烦。 What's the simplest way to run a python script with params on a web server? 在Web服务器上使用params运行python脚本的最简单方法是什么? I've tried Node, but had a lot of trouble with spawning child processes, tried PHP but ran into a similar problem and just couldn't get exec to work for even the simplest script. 我已经尝试过Node,但是在生成子进程时遇到了很多麻烦,尝试了PHP但是遇到了类似的问题,即使是最简单的脚本也无法让exec工作。 Just spent a while trying Django, but that turned out to be far too involved. 刚刚花了一段时间尝试Django,但事实证明它过于牵扯。 How can I do this without re-inventing the wheel? 如何在不重新发明轮子的情况下做到这一点?

For example, take the following request: 例如,请执行以下请求:

www.example.com/someprogram?foo=bar&bar=baz

And render the output from a script run with those params: 并使用这些参数运行脚本运行的输出:

python someprogram.py foo bar

Try bottle , a micro web framework: 试试瓶子 ,一个微型网络框架:

someprogram.py: someprogram.py:

def f(foo, bar):
    return "foo: {}, bar: {}"format(foo, bar)

server.py: server.py:

from bottle import route, run
import someprogram


@route('/')
def home():
    return someprogram.f(request.query.foo, request.query.bar)

if __name__ == "__main__":
    run(debug=True, reloader=True)

To run: 跑步:

pip install bottle
python server.py

Use subprocess.check_output() to spawn a process if you don't want to import someprogram.py . 如果您不想导入someprogram.py subprocess.check_output()生成进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Raspberry Pi Web服务器中从Web运行python脚本 - Run python script from the web in a Raspberry Pi web server 如何在 web 服务器上的 php 脚本上运行 python 文件? - How to run an python file on php script on web server? 有没有办法在托管Web服务器上使用cron自动运行PHP脚本? - Is there any way to automatically run PHP script on Hosting web server withour cron? 检查是否设置了多个 POST 参数的最简单方法? - Easiest way to check if multiple POST parameters are set? 在我的html页面上运行小型php脚本的最快,最简单的方法是什么? - What is the quickest and easiest way to run a small php script on my html page? 使PHP脚本在Web服务器上频繁运行 - Getting a PHP script to run frequently on a web server 在arduino上运行php脚本(作为Web服务器) - run php script on arduino (as a web server) 将基于服务器的错误消息返回到基于Web的模式面板的最简单方法是什么 - What is the easiest way to return server based error messages to a web based modal panel 允许python脚本创建文件的最佳/最简单的Apache服务器/文件夹设置是什么? - What are best/easiest Apache server/folder settings for allowing a python script to create a file? 获取服务器目录中文件列表的最简单方法 - Easiest way to get list of files in the server directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM