summaryrefslogtreecommitdiffstats
path: root/lib/System/Win32
diff options
context:
space:
mode:
Diffstat (limited to 'lib/System/Win32')
-rw-r--r--lib/System/Win32/Program.inc13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc
index 52eb967..7e97c7f 100644
--- a/lib/System/Win32/Program.inc
+++ b/lib/System/Win32/Program.inc
@@ -176,7 +176,14 @@ Program::ExecuteAndWait(const Path& path,
MakeErrMsg(ErrMsg, "can't redirect stdout");
return -1;
}
- if (redirects[1] && redirects[2] && *(redirects[1]) != *(redirects[2])) {
+ if (redirects[1] && redirects[2] && *(redirects[1]) == *(redirects[2])) {
+ // If stdout and stderr should go to the same place, redirect stderr
+ // to the handle already open for stdout.
+ DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
+ GetCurrentProcess(), &si.hStdError,
+ 0, TRUE, DUPLICATE_SAME_ACCESS);
+ } else {
+ // Just redirect stderr
si.hStdError = RedirectIO(redirects[2], 2, ErrMsg);
if (si.hStdError == INVALID_HANDLE_VALUE) {
CloseHandle(si.hStdInput);
@@ -184,10 +191,6 @@ Program::ExecuteAndWait(const Path& path,
MakeErrMsg(ErrMsg, "can't redirect stderr");
return -1;
}
- } else {
- DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
- GetCurrentProcess(), &si.hStdError,
- 0, TRUE, DUPLICATE_SAME_ACCESS);
}
}