]> granicus.if.org Git - php/commitdiff
Add optional array argument to proc_open() to specify additional
authorWez Furlong <wez@php.net>
Fri, 5 Dec 2003 13:45:00 +0000 (13:45 +0000)
committerWez Furlong <wez@php.net>
Fri, 5 Dec 2003 13:45:00 +0000 (13:45 +0000)
options for the child process.
The first option is "suppress_errors" which will disable any
dialog boxes that arise from missing DLL's and suppress the
GPF dialog.
Use this new feature in the test suite, so that crashing tests don't block the test run; useful for un-attended execution.

ext/standard/proc_open.c
run-tests.php

index daf498505078e9a3e9be9e8dbc9ee1ced059e3a8..d23bc4076ce85aa01c4075368c222399613e5106 100644 (file)
@@ -444,16 +444,16 @@ struct php_proc_open_descriptor_item {
 };
 /* }}} */
 
-/* {{{ proto resource proc_open(string command, array descriptorspec, array &pipes [, string cwd [, array env]])
+/* {{{ proto resource proc_open(string command, array descriptorspec, array &pipes [, string cwd [, array env] [, array other_options]])
    Run a process with more control over it's file descriptors */
 PHP_FUNCTION(proc_open)
 {
-
        char *command, *cwd=NULL;
        long command_len, cwd_len;
        zval *descriptorspec;
        zval *pipes;
        zval *environment = NULL;
+       zval *other_options = NULL;
        php_process_env_t env;
        int ndesc = 0;
        int i;
@@ -466,13 +466,16 @@ PHP_FUNCTION(proc_open)
        BOOL newprocok;
        SECURITY_ATTRIBUTES security;
        char *command_with_cmd;
+       UINT old_error_mode;
+       int suppress_errors = 0;
 #endif
        php_process_id_t child;
        struct php_process_handle *proc;
        int is_persistent = 0; /* TODO: ensure that persistent procs will work */
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz|s!a!", &command,
-                               &command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz|s!a!a!", &command,
+                               &command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment,
+                               &other_options) == FAILURE) {
                RETURN_FALSE;
        }
 
@@ -480,6 +483,15 @@ PHP_FUNCTION(proc_open)
                RETURN_FALSE;
        }
 
+       if (other_options) {
+               zval **item;
+               if (SUCCESS == zend_hash_find(Z_ARRVAL_P(other_options), "suppress_errors", sizeof("suppress_errors"), (void**)&item)) {
+                       if (Z_TYPE_PP(item) == IS_BOOL && Z_BVAL_PP(item)) {
+                               suppress_errors = 1;
+                       }
+               }       
+       }
+       
        command_len = strlen(command);
 
        if (environment) {
@@ -669,7 +681,17 @@ PHP_FUNCTION(proc_open)
        
        command_with_cmd = emalloc(command_len + sizeof(COMSPEC_9X) + 1 + sizeof(" /c "));
        sprintf(command_with_cmd, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command);
+
+       if (suppress_errors) {
+               old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
+       }
+       
        newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi);
+
+       if (suppress_errors) {
+               SetErrorMode(old_error_mode);
+       }
+       
        efree(command_with_cmd);
 
        if (FALSE == newprocok) {
index b1493f57297417df71d8390c5553bda71365e451..0b4f6afa133121136f691cdabefded3cf51888a0 100755 (executable)
@@ -117,6 +117,7 @@ if (getenv('TEST_PHP_EXECUTABLE')) {
                putenv("TEST_PHP_EXECUTABLE=$php");
        }
 }
+
 if (empty($php) || !file_exists($php)) {
        error("environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!");
 }
@@ -588,7 +589,7 @@ function system_with_timeout($commandline)
                0 => array('pipe', 'r'),
                1 => array('pipe', 'w'),
                2 => array('pipe', 'w')
-               ), $pipes);
+               ), $pipes, null, null, array("suppress_errors" => true));
 
        if (!$proc)
                return false;