Skip to content

Commit

Permalink
Merge pull request #1618 from CyberShadow/std-process-gui-spawnprocess
Browse files Browse the repository at this point in the history
std.process: Fix spawnProcess in Windows GUI programs (issue #11180)
  • Loading branch information
andralex committed Oct 9, 2013
2 parents 7875e39 + 24255bd commit e69f4dc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions std/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -485,18 +485,21 @@ private Pid spawnProcessImpl(in char[] commandLine,
version (DMC_RUNTIME) handle = _fdToHandle(fileDescriptor);
else /* MSVCRT */ handle = _get_osfhandle(fileDescriptor);
}

DWORD dwFlags;
GetHandleInformation(handle, &dwFlags);
if (!(dwFlags & HANDLE_FLAG_INHERIT))
if (GetHandleInformation(handle, &dwFlags))
{
if (!SetHandleInformation(handle,
HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT))
if (!(dwFlags & HANDLE_FLAG_INHERIT))
{
throw new StdioException(
"Failed to make "~which~" stream inheritable by child process ("
~sysErrorString(GetLastError()) ~ ')',
0);
if (!SetHandleInformation(handle,
HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT))
{
throw new StdioException(
"Failed to make "~which~" stream inheritable by child process ("
~sysErrorString(GetLastError()) ~ ')',
0);
}
}
}
}
Expand Down

0 comments on commit e69f4dc

Please sign in to comment.