From 6c35c644568eaabd57a7d7b950ed1ff72bd16a26 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 12 Sep 2015 09:33:55 -0700 Subject: [PATCH] Fixed windows redirection not replacing standard file pointers --- src/posix-compat.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/posix-compat.c b/src/posix-compat.c index eb2ba3d..2b0c6a7 100644 --- a/src/posix-compat.c +++ b/src/posix-compat.c @@ -524,7 +524,14 @@ void cr_redirect(int fd_kind, s_pipe_handle *pipe, int fd_index, int noblock) { cr_std_fd fd = get_std_fd(fd_kind); #ifdef VANILLA_WIN32 CloseHandle(GetStdHandle(fd)); + _close(fd_kind); SetStdHandle(fd, pipe->fhs[fd_index]); + + fflush(NULL); + FILE *stdf = fd_kind == 0 ? pipe_in(pipe, 0) : pipe_out(pipe, 0); + if (stdf == NULL) + cr_assert_fail("Could not redirect standard file descriptor."); + _dup2(_fileno(stdf), fd_kind); #else close(fd); dup2(pipe->fds[fd_index], fd);