From: colin AT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters) Subject: RE: Right way in Win32 to redirect child process stdout? 2 Oct 1998 15:40:16 -0700 Message-ID: <00ac01bdedcc$e3f5f3e0$fa173185.cygnus.gnu-win32@gbird0.fu.is.saga-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit To: "Igor boukanov" Cc: "GNU-win32" One way to do it is to set the hStdOutput handle in the STARTUPINFO structure passed to CreateProcess instead of reassigning your own standard output and then starting the child. You also have to set the flag STARTF_USESTDHANDLES and set the hStdInput and hStdError (but you can set them to your own, or not, as you wish). Also fInheritHandles must be TRUE. If you do it this way you don't have to reset your own standard handles, and therefore you can avoid the whole issue of having other threads have their output accidentally redirected. Colin. PS. This is all from the Win32 documentation, although I have also done it myself it was some time ago, so I hope there are no hidden gotchas. - Colin Peters - colin at fu.is.saga-u.ac.jp - http://www.geocities.com/Tokyo/Towers/6162/index.html - Go not to usenet for counsel, for it will say both - 'yes' and 'no' and 'try another newsgroup'. -----Original Message----- Igor boukanov wrote: [snip] >I need to create a process with redirected output by the mean of Win32 API. Unfortunately, a straightforward approach: > >... >HANDLE old = GetStdHandle(STD_OUTPUT_HANDLE); >SetStdHandle(STD_OUTPUT_HANDLE, redirection_handle); >CreateProcess(...); >SetStdHandle(STD_OUTPUT_HANDLE, old); >... > >does not work in multithreading program because there is a chance that some thread will write to stdout between SetStdHandle and CreateProcess >spoiling child output to redirection_handle. [snip] - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".