From 36da54e6e7331b9ba319c3bf6663446b3d968a34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 16 Mar 2017 13:23:15 -0400 Subject: [PATCH] exec: close child pipes from the parent process MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/core/exec.nit | 6 +++++- tests/sav/test_exec.res | 3 ++- tests/test_exec.nit | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/core/exec.nit b/lib/core/exec.nit index d5ab952..fedc5de 100644 --- a/lib/core/exec.nit +++ b/lib/core/exec.nit @@ -164,7 +164,7 @@ class Process return NULL; } start_info.hStdInput = in_fd[0]; - result->in_fd = _open_osfhandle((intptr_t)in_fd[1], _O_APPEND); + result->in_fd = _open_osfhandle((intptr_t)in_fd[1], _O_WRONLY); if ( !SetHandleInformation(in_fd[1], HANDLE_FLAG_INHERIT, 0) ) return NULL; } else { @@ -214,6 +214,10 @@ class Process &start_info, &proc_info); + if (pipeflag & 1) CloseHandle(in_fd[0]); + if (pipeflag & 2) CloseHandle(out_fd[1]); + if (pipeflag & 3) CloseHandle(err_fd[1]); + // Error? if (!created) { result->running = 0; diff --git a/tests/sav/test_exec.res b/tests/sav/test_exec.res index 3647533..fcfb6f7 100644 --- a/tests/sav/test_exec.res +++ b/tests/sav/test_exec.res @@ -1,7 +1,8 @@ A hello world! 0 -B hello world!0 +B hello world!true +0 C hello world! 0 diff --git a/tests/test_exec.nit b/tests/test_exec.nit index efb94b7..58b6343 100644 --- a/tests/test_exec.nit +++ b/tests/test_exec.nit @@ -24,6 +24,7 @@ print "" var ip = new ProcessReader("echo", "B hello world!") ip.read_line.output +ip.eof.output ip.wait print ip.status -- 1.7.9.5