Hey everyone
I have the following code that I want to use on my web server to pipe output from a CGI interpreter (such as PHP).
Now, for some reason when this runs I am told there is an illegal operation, and the service (it runs as an NT service) has to shut down.Code:// Assume that Extension = "php"; Options.CGI[Extension] = "c:\\PHP\\php.exe"; RealFile = "c:\\webroot\\sample.php"; bool CONNECTION::SendCGI() { char psBuffer[128]; FILE * hPipe; string CGIInterpreter = "\""; // Put quotes around the name of the interpreter CGIInterpreter += Options.CGI[Extension]; // Interpreter CGIInterpreter += "\" "; // End quote CGIInterpreter += RealFile; // Add the file to be interpreted if ((hPipe = _popen(CGIInterpreter.c_str(), "rt")) == NULL) { // Open a pipe send (SFD, "Content-type: text/html\n\nCouldn't open pipe :(",48, 0); } else { while (!feof( hPipe )) // Loop until output finishes { if( fread( psBuffer,1, 128, hPipe) ) // Get part of the output { send (SFD, psBuffer, 128, 0); // Send it } } fclose(hPipe); // Close pipe } return true; }
No output is ever sent to the client. Am I doing something wrong with the pointers? I don't like to use FILE *'s but this was the only example I could find to use _popen().
If anyone has any other easier ways I could create a pipe (win32) or if you can see what I've done wrong with my code, I'd love to hear from you.



LinkBack URL
About LinkBacks


