Hi all,

I'm having a problem tying to get CGI to work. I am using Neko, a nice open source programming language, with which I produce an executable. You're probably not familiar but the syntax is very easy:

Code:
class Main {
        static function main() {
                var fi = File.stdin();
                var str = '' + Sys.environment();
                var w = File.write("M:\\Apache2.2\\htdocs\\test.txt", true);
                w.writeString(str);
                w.close();
               
                var fo = File.stdout();
                fo.writeString("Content-type: text/html\r\n\r\n");
                fo.writeString("Hello world");
                fo.close();
        }
}
I compiled it to a index.exe, and then renamed it to index.cgi. Then I copied this file to the /htdocs directory of Apache and made sure I enabled cgi by specifying 'Options +ExecCGI' in the htaccess file.

When I tested the file by visiting http://localhost/index.cgi I got a '500 Internal Server Error'. The error logs revealed the following line: '[Sat Apr 10 10:43:28 2010] [error] [client 127.0.0.1] Premature end of script headers: index.cgi'

After consulting Google, I found out that the error would probably mean index.cgi doesn't output the correct headers, but I'm pretty sure it does. Also, it should write a test.txt file if the file gets executed at all, because it happens before generating any output. However, no file is created which indicates that index.cgi doesn't get run at all.

When I open a command prompt and execute the index.cgi manually, the test.txt file is created and the following (correct) output is shown:
Code:
Content-type: text/html

Hello world
Here are the relevant settings of my Apache config file:
Code:
..
<IfModule dir_module>
    DirectoryIndex index.cgi index.html
</IfModule>
..
<IfModule mime_module>
    AddHandler cgi-script .cgi
</IfModule>
...
I always thought you could use any executable file for CGI as long as it produces the correct output to stdout. Am I wrong at this? I have double checked all my settings and don't understand what is wrong otherwise.

What could be wrong?

Regards,
Bas