I need a plumber :P (Problems with Pipes)
Hey everyone. I have the following function that is part of my CONNECTION class:
Code:
int CONNECTION::SendCGI()
{
RealFile = "C:\\SWS\\Webroot\\samplephp.php";
char psBuffer[128];
FILE * hPipe;
string CGIInterpreter = "\""; // Put quotes around the name of the interpreter
CGIInterpreter += "C:\\PHP\\php.exe"; // Interpreter
CGIInterpreter += "\" "; // End quote
CGIInterpreter += RealFile; // Add the file to be interpreted
if ((hPipe = _popen(CGIInterpreter.c_str(), "r")) == NULL)
{ // Open a pipe
Beep(80,1000);
}
else
{
while (!feof( hPipe )) // Loop until output finishes
{
if( fgets( psBuffer, 128, hPipe) ) // Get part of the output
{
cout << psBuffer; // Send it
}
}
fclose(hPipe); // Close pipe
} // Return true for now
return true;
}
The code runs as part of an NT service and is supposed to send a file to a CGI interpreter and pipe its output to be sent back to the browser.
When that code is run from the server all I get is the beep. But if I copy everything from the function and run it inside 'main()' as part of a stand alone application it runs fine and gives the expected output.
I don't use any of the variables externally (for now, I will when its working) yet it wont work when run as a service.
Theres nothing wrong with the service code or anything because I can do everything else, just not this. Does anyone have any idea why I might be having these problems?
[edit] lol damn typo in the title, now no one will read it[/edit]