|
From: neilsolent on 28 May 2008 16:07 I am using the CreateProcess() function to create a child process that writes its stdout to a file. I am opening the output file in the parent process, then passing it to the child via the lpStartupInfo parameter of CreateProcess(), and by specifying TRUE for the bInheritHandles parameter. This works fine, except that the child process also inherits handles that I don't want it to - for example sockets that the parent process may have open! Is there a way (of achieving a child process writing to stdout to a file) without setting bInheritHandles to TRUE? thanks, Neil
From: Doug Harrison [MVP] on 28 May 2008 16:20 On Wed, 28 May 2008 13:07:35 -0700 (PDT), neilsolent <neil(a)solenttechnology.co.uk> wrote: >I am using the CreateProcess() function to create a child process that >writes its stdout to a file. > >I am opening the output file in the parent process, then passing it to >the child via the lpStartupInfo parameter of CreateProcess(), and by >specifying TRUE for the bInheritHandles parameter. > >This works fine, except that the child process also inherits handles >that I don't want it to - for example sockets that the parent process >may have open! > >Is there a way (of achieving a child process writing to stdout to a >file) without setting bInheritHandles to TRUE? It's possible to specify that handles won't be inherited when you create them. See for example CreateFile's lpSecurityAttributes parameter. Beyond this, to disallow inheritance in CreateProcess, I believe the child process would have to assist in the handle transfer in some scheme involving DuplicateHandle. -- Doug Harrison Visual C++ MVP
From: neilsolent on 28 May 2008 16:38 > It's possible to specify that handles won't be inherited when you create > them. See for example CreateFile's lpSecurityAttributes parameter. Beyond > this, to disallow inheritance in CreateProcess, I believe the child process > would have to assist in the handle transfer in some scheme involving > DuplicateHandle. Thanks Doug. I know I can specify handles to not be inherited, but that would be messy coding to be honest (for example, there might be a handle implicity created inside a function that isn't immediately obvious).
From: Norman Bullen on 28 May 2008 21:18 neilsolent wrote: > I am using the CreateProcess() function to create a child process that > writes its stdout to a file. > > I am opening the output file in the parent process, then passing it to > the child via the lpStartupInfo parameter of CreateProcess(), and by > specifying TRUE for the bInheritHandles parameter. > > This works fine, except that the child process also inherits handles > that I don't want it to - for example sockets that the parent process > may have open! > > Is there a way (of achieving a child process writing to stdout to a > file) without setting bInheritHandles to TRUE? > > thanks, > Neil Do you have access to the code for the child process? Is so, you can simply pass the name of the output file as a command line parameter and modify the process so that it opens the file and writes to it as a file rather than as standard output. (There are also C and C++ library functions which can link the handle of an open file to the standard output name.) If you can't modify the child process, create an intermediate child process which simply opens a file the name of which is a command line parameter with inherit ability enabled and then calls CreateProcess() to start the original child process. -- Norm To reply, change domain to an adult feline.
From: neilsolent on 29 May 2008 04:09 > If you can't modify the child process, create an intermediate child > process which simply opens a file the name of which is a command line > parameter with inherit ability enabled and then calls CreateProcess() to > start the original child process. I can't modify the child process - user supplied scripts An intemediary - that's a good idea - hadn't thought of it. Suspect that is quite a common approach. I might give that a go. I can't believe how difficult it is to do something that seemed so simple!
|
Pages: 1 Prev: Attaching a control to a CDialog Next: GDI+ Image::Save() function returns InvalidParameter |