I need a plumbep :P (Problems with Pipes)

This is a discussion on I need a plumbep :P (Problems with Pipes) within the C++ Programming forums, part of the General Programming Boards category; Hey everyone. I have the following function that is part of my CONNECTION class: Code: int CONNECTION::SendCGI() { RealFile = ...

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    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]
    Last edited by nickname_changed; 07-13-2003 at 08:41 AM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    From MSDN
    Note If used in a Windows program, the _popen function returns an invalid file pointer that will cause the program to hang indefinitely. _popen works properly in a Console application. To create a Windows application that redirects input and output, see Creating a Child Process with Redirected Input and Output in the Platform SDK.
    http://msdn.microsoft.com/library/de...c_._wpopen.asp
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Yeah I've read that before on MSDN actually, but as an NT service its supposed to be a console application. It is called though main just like a normal console app. and is compiled in the same way, so I didn't think that would be a problem.

    The server doesn't hang though, it goes though very fast and beeps because the pipe couldn't be created (but when run as a non-serivce it doesn't).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problems with multiple pipes.
    By LightsOut06 in forum Linux Programming
    Replies: 3
    Last Post: 12-02-2010, 01:38 PM
  2. Pipes sometimes fail
    By EVOEx in forum Linux Programming
    Replies: 2
    Last Post: 05-02-2009, 01:47 PM
  3. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. Services and Pipes
    By nickname_changed in forum Windows Programming
    Replies: 0
    Last Post: 07-16-2003, 06:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21