Raspberry pi Python shebang with cgi server

痞子三分冷 提交于 2020-01-05 13:13:57

问题


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

Server.py

cgi-bin

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

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"

in order to do this i have tried multiple shebangs:

#!/usr/bin/env python

#!/usr/bin/python

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

to clarify i am using:

python 2.7.3rc2

standard raspi linux distro "wheezy"

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.

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

#!/usr/bin/python

print "Hello World!"

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

/test.py

from the command line and i get:

print: bad interpreter: No such file or directory

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

Thanks

James


回答1:


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

E.g. see How to convert Windows end of line in Unix end of line (CR/LF to LF)



来源:https://stackoverflow.com/questions/22169908/raspberry-pi-python-shebang-with-cgi-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!