1
votes

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
what's the output of which python - user1937198
which python outputs: /usr/bin/python - James Kent
Did you try python test.py ? Just to test. - VivienG
python test.py works as expected - James Kent
In your Question you type /test.py don't forget the . before ! ./test.py But it's not that. You can launch your script everywhere you whant with python test.py - VivienG

1 Answers

-1
votes

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)

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