Skip to content

Commit ef43288

Browse files
committed
git-wrapper: inherit stdin/stdout/stderr even without a console
Otherwise the output of Git commands cannot be caught by, say, Git GUI (because it is running detached from any console, which would make `git.exe` inherit the standard handles implicitly). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent dcef1dd commit ef43288

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compat/win32/git-wrapper.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,33 @@ int main(void)
243243
{
244244
STARTUPINFO si;
245245
PROCESS_INFORMATION pi;
246+
DWORD creation_flags = CREATE_UNICODE_ENVIRONMENT;
247+
HANDLE console_handle;
246248
BOOL br = FALSE;
247249
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
248250
ZeroMemory(&si, sizeof(STARTUPINFO));
249251
si.cb = sizeof(STARTUPINFO);
252+
253+
console_handle = CreateFile(L"CONOUT$", GENERIC_WRITE,
254+
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
255+
FILE_ATTRIBUTE_NORMAL, NULL);
256+
if (console_handle != INVALID_HANDLE_VALUE)
257+
CloseHandle(console_handle);
258+
else {
259+
si.dwFlags = STARTF_USESTDHANDLES;
260+
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
261+
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
262+
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
263+
264+
creation_flags |= CREATE_NO_WINDOW;
265+
}
250266
br = CreateProcess(/* module: null means use command line */
251267
exep,
252268
cmd, /* modified command line */
253269
NULL, /* process handle inheritance */
254270
NULL, /* thread handle inheritance */
255271
TRUE, /* handles inheritable? */
256-
CREATE_UNICODE_ENVIRONMENT,
272+
creation_flags,
257273
NULL, /* environment: use parent */
258274
dir, /* starting directory: use parent */
259275
&si, &pi);

0 commit comments

Comments
 (0)