带有 cgi 服务器的 Raspberry pi Python shebang [英] Raspberry pi Python shebang with cgi server

查看:67
本文介绍了带有 cgi 服务器的 Raspberry pi Python shebang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 raspberry pi 上运行本地 CGI 服务器以托管一个带有单个链接的网页,该链接指向一个 CGI 脚本,该脚本应该触发另一个脚本,然后打印 HTML 代码以重定向回起始页面(以免挂起)

I am trying to run a local CGI server on my raspberry pi to host a webpage with a single link, that link is to a CGI script which is supposed to trigger another script and then print HTML code to redirect back to the starting page (so that it doesn't hang)

在我的服务器根目录中:

in the servers root directory i have:

index.html

favicon.ico

favicon.ico

服务器.py

cgi-bin

我的服务器设置为将 cgi-bin 文件夹用于 cgi-scripts.

my server is set up to use the cgi-bin folder for cgi-scripts.

我遇到的问题是我似乎无法使脚本可调用,因此我应该能够输入Server.py"而不是键入python Server.py"

the issue i am having is i cannot seem to make the scripts callable, is so instead of typing "python Server.py" i should be able to type "Server.py"

为了做到这一点,我尝试了多个shebangs:

in order to do this i have tried multiple shebangs:

#!/usr/bin/env python

#!/usr/bin/python

然后调用chmod a+x Server.py 将其标记为可执行文件,但无济于事.

and then called chmod a+x Server.py to mark it as executable, to no avail.

澄清我正在使用:

python 2.7.3rc2

python 2.7.3rc2

标准的 raspi linux 发行版wheezy"

standard raspi linux distro "wheezy"

我在一些帮助文档中读到,如果文件有 DOS 样式的换行符,它会干扰 shebang,所以我确保它们现在是 MAC 样式的换行符,这仍然不起作用.

i read in some of the help docs that if the file has DOS style newlines it interferes with the shebang, so i have ensured that they are now MAC style newlines, this still did not work.

为了进一步测试,我制作了一个简单的 python 文件,其中包含:

to test further i have made a simple python file which contains:

#!/usr/bin/python

print "Hello World!"

将其保存为 test.py,将其标记为可执行文件,然后尝试:

saved it as test.py, marked it as executable, and tried:

/test.py

从命令行,我得到:

打印:错误的解释器:没有那个文件或目录

print: bad interpreter: No such file or directory

谁能告诉我我哪里出错了?

can someone please tell me where i'm going wrong?

谢谢

詹姆斯

推荐答案

尝试删除脚本中的 windows 行尾.这使它对我有用.

Try to remove windows line endings in the script. This made it work for me.

例如见 如何在 Unix 行尾(CR/LF 到 LF)中转换 Windows 行尾

有关此问题的更多可能原因,请在此处查看我的回答 https://stackoverflow.com/a/65249192/1150303

For more possible causes of this problem have look at my answer here https://stackoverflow.com/a/65249192/1150303

这篇关于带有 cgi 服务器的 Raspberry pi Python shebang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆