Add stderr redirection for native linux programs started from windows program

Igor Egorov atohom at gmail.com
Fri Feb 4 20:47:10 CST 2011


---
 dlls/kernel32/process.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 0bc77c9..4ef8f2a 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1449,7 +1449,7 @@ static char **build_envp( const WCHAR *envW )
 static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHAR *env,
                           const char *newdir, DWORD flags, STARTUPINFOW *startup )
 {
-    int fd[2], stdin_fd = -1, stdout_fd = -1;
+    int fd[2], stdin_fd = -1, stdout_fd = -1, stderr_fd = -1;
     int pid, err;
     char **argv, **envp;
 
@@ -1470,25 +1470,30 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHA
 
     if (!(flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
     {
-        HANDLE hstdin, hstdout;
+        HANDLE hstdin, hstdout, hstderr;
 
         if (startup->dwFlags & STARTF_USESTDHANDLES)
         {
             hstdin = startup->hStdInput;
             hstdout = startup->hStdOutput;
+            hstderr = startup->hStdError;
         }
         else
         {
             hstdin = GetStdHandle(STD_INPUT_HANDLE);
             hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
+            hstderr = GetStdHandle(STD_ERROR_HANDLE);
         }
 
         if (is_console_handle( hstdin ))
             hstdin = wine_server_ptr_handle( console_handle_unmap( hstdin ));
         if (is_console_handle( hstdout ))
             hstdout = wine_server_ptr_handle( console_handle_unmap( hstdout ));
+        if (is_console_handle( hstderr ))
+            hstderr = wine_server_ptr_handle( console_handle_unmap( hstderr ));
         wine_server_handle_to_fd( hstdin, FILE_READ_DATA, &stdin_fd, NULL );
         wine_server_handle_to_fd( hstdout, FILE_WRITE_DATA, &stdout_fd, NULL );
+        wine_server_handle_to_fd( hstderr, FILE_WRITE_DATA, &stderr_fd, NULL );
     }
 
     argv = build_argv( cmdline, 0 );
@@ -1527,6 +1532,11 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHA
                 dup2( stdout_fd, 1 );
                 close( stdout_fd );
             }
+            if (stderr_fd != -1)
+            {
+                dup2( stderr_fd, 2 );
+                close( stderr_fd );
+            }
         }
 
         /* Reset signals that we previously set to SIG_IGN */
@@ -1544,6 +1554,7 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHA
     HeapFree( GetProcessHeap(), 0, envp );
     if (stdin_fd != -1) close( stdin_fd );
     if (stdout_fd != -1) close( stdout_fd );
+    if (stderr_fd != -1) close( stderr_fd );
     close( fd[1] );
     if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0))  /* exec failed */
     {
-- 
1.7.1


--------------040607070803070307080002--



More information about the wine-patches mailing list