1

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

James Kent
  • 5,763
  • 26
  • 50
  • 2
    what's the output of `which python` – user1937198 Mar 04 '14 at 10:57
  • which python outputs: /usr/bin/python – James Kent Mar 04 '14 at 11:21
  • Did you try `python test.py` ? Just to test. – VivienG Mar 04 '14 at 11:25
  • python test.py works as expected – James Kent Mar 04 '14 at 11:46
  • 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 Mar 04 '14 at 11:55
  • i tried bash test.py which gave me no output at all, i've just uninstalled python and reinstalled it, still no success, i need these files to execute on their own as thats how the cgi server calls them... – James Kent Mar 04 '14 at 11:57
  • Sorry, that's my bad, it's `bash -c ./test.py` – VivienG Mar 04 '14 at 11:58
  • @JamesKent Also can you give us the result of this `echo $PATH` please. – VivienG Mar 04 '14 at 12:00
  • bash -c ./test.py gave me: bash: ./test.py: No such file or directory and echo $PATH gives: /usr/bin/sbin:/usr/local/bin:/usr/bin:/sbin:/bin – James Kent Mar 04 '14 at 12:04
  • OK, that's weird looks like you have problem with bash :/ Can you just use  `python ./test.py` for your usage ? I think I'm not able to help your more, may be try `bash --version` and print the result here, you may have a limited version. – VivienG Mar 04 '14 at 12:11
  • unfortunately because of the way the cgi server calls the script i cant do that, it has to work properly by only typing the script name :/ and i will do, however my screen has been borrowed for the moment... – James Kent Mar 04 '14 at 13:16

1 Answers1

-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)

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

DomTomCat
  • 8,189
  • 1
  • 49
  • 64