From: Pierre Joye Date: Tue, 9 Jun 2009 00:25:37 +0000 (+0000) Subject: #41874, separate STDOUT and STDERR in exec functions X-Git-Tag: php-5.3.0RC3~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49666eece6b8d5de74f1bae2537e8cc3919203ee;p=php #41874, separate STDOUT and STDERR in exec functions --- diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 7eb18b29d3..027e20b2ae 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -251,6 +251,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, PROCESS_INFORMATION process; SECURITY_ATTRIBUTES security; HANDLE in, out; + DWORD dwCreateFlags = 0; char *cmd; process_pair *proc; TSRMLS_FETCH(); @@ -273,7 +274,6 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, read = (type[0] == 'r') ? TRUE : FALSE; mode = ((str_len == 2) && (type[1] == 'b')) ? O_BINARY : O_TEXT; - if (read) { in = dupHandle(in, FALSE); startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE); @@ -284,9 +284,14 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, startup.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); } + dwCreateFlags = NORMAL_PRIORITY_CLASS; + if (strcmp(sapi_module.name, "cli") != 0) { + dwCreateFlags |= CREATE_NO_WINDOW; + } + cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2); sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command); - if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env, cwd, &startup, &process)) { + if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process)) { return NULL; } free(cmd); diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index b7f6c67fb8..584d175a43 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -483,6 +483,7 @@ PHP_FUNCTION(proc_open) STARTUPINFO si; BOOL newprocok; SECURITY_ATTRIBUTES security; + DWORD dwCreateFlags = 0; char *command_with_cmd; UINT old_error_mode; #endif @@ -754,12 +755,17 @@ PHP_FUNCTION(proc_open) old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX); } + dwCreateFlags = NORMAL_PRIORITY_CLASS; + if(strcmp(sapi_module.name, "cli") != 0) { + dwCreateFlags |= CREATE_NO_WINDOW; + } + if (bypass_shell) { - newprocok = CreateProcess(NULL, command, &security, &security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi); + newprocok = CreateProcess(NULL, command, &security, &security, TRUE, dwCreateFlags, env.envp, cwd, &si, &pi); } else { spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command); - newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi); + newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, dwCreateFlags, env.envp, cwd, &si, &pi); efree(command_with_cmd); } diff --git a/ext/standard/tests/file/bug41874.phpt b/ext/standard/tests/file/bug41874.phpt new file mode 100644 index 0000000000..c6f9fed675 --- /dev/null +++ b/ext/standard/tests/file/bug41874.phpt @@ -0,0 +1,22 @@ +--TEST-- +bug #41874 (Separate STDOUT and STDERR in exec functions) +--CREDITS-- +Venkat Raman Don +--SKIPIF-- + +--FILE-- + +--EXPECT-- +The system cannot find the drive specified. +The system cannot find the drive specified. +The system cannot find the drive specified. diff --git a/ext/standard/tests/file/bug41874_1.phpt b/ext/standard/tests/file/bug41874_1.phpt new file mode 100644 index 0000000000..c6ddef8066 --- /dev/null +++ b/ext/standard/tests/file/bug41874_1.phpt @@ -0,0 +1,16 @@ +--TEST-- +bug #41874 (Separate STDOUT and STDERR in exec functions) +--CREDITS-- +Venkat Raman Don +--SKIPIF-- + +--FILE-- + +--EXPECT-- +The system cannot find the drive specified. \ No newline at end of file diff --git a/ext/standard/tests/file/bug41874_2.phpt b/ext/standard/tests/file/bug41874_2.phpt new file mode 100644 index 0000000000..5d7b7cad8d --- /dev/null +++ b/ext/standard/tests/file/bug41874_2.phpt @@ -0,0 +1,17 @@ +--TEST-- +bug #41874 (Separate STDOUT and STDERR in exec functions) +--CREDITS-- +Venkat Raman Don +--SKIPIF-- + +--FILE-- + +--EXPECT-- +The system cannot find the drive specified. \ No newline at end of file diff --git a/ext/standard/tests/file/bug41874_3.phpt b/ext/standard/tests/file/bug41874_3.phpt new file mode 100644 index 0000000000..4d7b139ad7 --- /dev/null +++ b/ext/standard/tests/file/bug41874_3.phpt @@ -0,0 +1,16 @@ +--TEST-- +bug #41874 (Separate STDOUT and STDERR in exec functions) +--CREDITS-- +Venkat Raman Don +--SKIPIF-- + +--FILE-- + +--EXPECT-- +The system cannot find the drive specified. \ No newline at end of file