Python CGI test on a shell account

software development

#1

I’m having problems testing CGI scripts from a shell account (not the website account – a user account). Every time I try to open it directly (“lynx hello.py”) or have information passed to it (“lynx *html” passes to *.py), it either complains that it cannot open the file or it simply displays the text contained in the script.

Is there any way to fix this?


#2

CGi doesn’t work that way. CGI involves having the operating system execute a binary executable (machine code) which processes input and generates output. This happens in a CGI enironment, where the web server is a gateway in which special environment variables are used.

The script file is text data. It is not a binary executable. The script file needs to be loaded by ‘python’, which is a binary executable. The ‘python’ executable compiles the script into bytecode and “runs” the bytecode using a virtual machine.

The command ‘lynx hello.py’ does not do that. It simply tells lynx to open the file as text.

The command ‘python hello.py’ will try to execute the script, but since it would not be running in a CGI environment, the script will most likely fail or not work as expected.

To execute the script in a CGI environment, you need a web server. Then you need to access the script through the web server. And to do that, you need a URL.

Thus the command you want to use is: ‘lynx http://example.com/hello.py

Scripts can be written to pretend they are in a CGI environment, so that you don’t have to use a web server. If you are not familiar with CGI environment, then you have a lot of reading to do.

Start with Dynamic Content with CGI

:cool: Perl / MySQL / HTML+CSS


#3

Damn, I was hoping that lynx would automatically execute it …

Most of what I was going to be doing was just text output/formatting, so by making a slight modification to the script, I found that running “./script.py > script_nme.html; lynx script_nme.html” would show the output pretty well (heh, I’m so silly ^^).