I am using PHP 5.1.4 CGI, Apache 2.0.53 on Windows 2000.

    $ret = shell_exec("pause");

echo($ret);

The above script should cause the php process to hang. However, the command is terminated immediatley. The problem is, is that when executing another program, it does not have enough time to run as PHP/Apache is terminating it the second it has started.

Is there something I am missing here? The httpd.conf file doesn't seem have any settings that restrict what programs a CGI script can run and I cannot seem to find any literature on restrictions imposed by apache on CGI programs.

    I'm still not getting an idea of your problem. Pause will run, which you can test like this

    exec('pause', $out, $ret);
    
    echo '<pre>'.print_r($out, 1).'</pre>';
    
    echo '<br />Done';
    
    // or even echo `pause`;
    

    But you're right in that it doesn't wait in this particular case.

      I just used pause as an example. I thought that pause would cause the script to hang.

      I did some further investigation into the problem by writing a small batch script and have apache execute it. If I attempt to run any program from within the batch script it spawns a new process and the old continues to run. It appears that if if the process running the CGI finishes before the process it has spawned, it will terminate it (logical if it is a child process).

      This is not what i want however, I need the program to run and want to grab its output. Hence the script needs to wait for it to finish. The appears to be an Apache issue; however there does not appear to be any settings which control how a cgi script should execute other programs.

        See if this works. I wemmed about with all the exec stuff ages ago and this is from my stack of examples I keep, can you use this instead?

        <?php
        /**
        *	For a command like notepad to show a window when running under apache as a service
        *	have to set the option 'Allow apache to interact with desktop' in the log on tab
        *	in services.  Restart the service each time a 
        */
        
        
        shell_it('notepad.exe', 1, true);
        
        echo "I'm done at: ".date('r');
        
        
        /**
        *	exec, shell_exec and backticks getting you down?
        *
        *	@param string command to run
        *	@param int window style
        *	@param bool wait before returning - set to false and it will run in bg
        */
        
        function shell_it($cmd, $winStyle = 0, $waitOnReturn = false)
        {
        	$WshShell = new COM("WScript.Shell");
        	$oExec = $WshShell->Run($cmd, $winStyle, $waitOnReturn);
        	$WshShell->Release();
        
        return $oExec;
        }
        
        /*
        Ok modes Actually here: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/wsh/htm/wsMthRun.asp
        
        0 Hide the window and activate another window.
        1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time.
        2 Activate & minimize.
        3 Activate & maximize.
        4 Restore. The active window remains active.
        5 Activate & Restore.
        6 Minimize & activate the next top-level window in the Z order.
        7 Minimize. The active window remains active.
        8 Display the window in its current state. The active window remains active.
        9 Restore & Activate. Specify this flag when restoring a minimized window.
        10 Sets the show-state based on the state of the program that started the application
        
        If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.
        
        If bWaitOnReturn is not specified or FALSE, this method immediately returns to script execution 
        rather than waiting on the process termination (and returns an error code of 0)
        
        Specifying the bWaitOnReturn parameter allows you to run programs synchronously (one at a time).
        
        Using 0 never shows a phpcli window at all in the taskbar
        Using 7 shows it, but just in the task bar, it doesn't focus
        */
        ?>
          Write a Reply...