views:

11

answers:

1

In unix I know the routine: between fork() and exec() in the child I close everything except stdin/out/err, so that all the open ports or files are not passed to the program I want to run.

But how do I do this in windows? In my case I'm implementing a DLL in C/C++, and I need to close both some files I opened (indirectly via some objects) and the sockets opened by the Application that loaded the dll, so that these open file handles are not passed to the application I'm spawning. The app doesn't pass those handles to the DLL, as my code shouldn't need those...

So far the code simply calles _spawnl(_P_NOWAIT, "foo.exe", "foo.exe", "arg1", "arg2",NULL); Visual Studio 2008 if that matters.

Thanks for your help.

A: 

hmm - sorry to be guessing here a little, but are you sure spawnl in Windows passes the open file handles?

If so, maybe you want to look at CreateProcess, and StartupInfo - these allow finer control over what gets passed/inherited to the new process

Jeff