Question

My C Program Code:

#include <stdio.h>
int main(void) {
  printf("Content-Type: text/plain;charset=us-ascii\n\n");
  printf("Hello world\n\n");
  return 0;
}

I compiled it several times, using the commands:

gcc -o first.cgi first.c
gcc first.c -o first.cgi
g++ first.c -o first.cgi

When I use first.cgi in my web it gives error:

  • CGI Error

    The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
    Unrecognized character \x90 at J:\KKS_Sawdagger\cgi-bin\first.cgi line 1.

Can anyone give me the reason please?

Was it helpful?

Solution

One possibility is that HTTP requires lines ended with CRLF ("\r\n"); so do most Internet protocols using lines, in fact.

Now, there are some mitigating observations that may apply to your code. The C standard says that text streams should convert from local native line endings to \n on input and from \n to local native line endings on output. The question would be 'Is stdout a text stream or a binary stream on Windows?', and that is a question to which I don't know the answer (but 'text' is a plausible guess - in which case the code should work fine on Windows).

Since the error message identifies the problem as a byte 0x90, which is not shown in the code, there is probably something else at play here. Have you run the program directly yourself?

Doesn't the extension for an executable need to be .exe on Windows? It might be that cmd.exe or some other command interpreter is being given your program to interpret as a script of some sort, and it isn't liking it very much. (That said, ISTR that GCC on Windows adds the .exe suffix, so the actual outputs from your compilations is first.cgi.exe.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top