Question about redirection handles in wcmd

Erich Hoover ehoover at
Sun Feb 8 15:34:48 CST 2009

On Sat, Feb 7, 2009 at 2:09 PM, Erich Hoover <ehoover at> wrote:

> I tracked down an issue where an application was running into a sharing
> problem in WCMD_execute when it created redirects to the same file more than
> once.  I originally hacked around this issue by changing the sharing mode
> for redirects, but I've now narrowed down the issue.  I discovered that the
> file handle is not being closed when a command has completed and that this
> issue is caused by the "old handle" value being INVALID_HANDLE_VALUE:
> The "old handle" value is being set to this because of a call to
> GetStdHandle (you see, GetStdHandle(STD_OUTPUT_HANDLE) ==
> So, my question is whether the call to GetStdHandle is important.  If not
> then line 1399 can easily be simplified to:
> old_stdhandles[handle] = idx_stdhandles[handle];
> Make this change resolves the sharing issue that I'm seeing, but if it is
> important to use GetStdHandle there then instead the "cleanup" code located
> near line 1562 needs to be more intelligent.
> Erich Hoover
> ehoover at

Looking at this a little more it appears that
GetStdHandle(STD_OUTPUT_HANDLE) is not normally supposed to be
INVALID_HANDLE_VALUE.  This appears to be happening in this case because
cmd.exe was launched in such a way that it has no input and output handles.
So, it appears to me that when cmd.exe is launched without stdin and stdout
handles that no handle cleanup occurs for redirects (causing the problem
I've been experiencing).  Does this sound right to anyone?

Erich Hoover
ehoover at
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the wine-devel mailing list