exec: close child pipes from the parent process
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 16 Mar 2017 17:23:15 +0000 (13:23 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 17 Mar 2017 15:44:17 +0000 (11:44 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/core/exec.nit
tests/sav/test_exec.res
tests/test_exec.nit

index d5ab952..fedc5de 100644 (file)
@@ -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;
index 3647533..fcfb6f7 100644 (file)
@@ -1,7 +1,8 @@
 A hello world!
 0
 
-B hello world!0
+B hello world!true
+0
 
 C hello world!
 0
index efb94b7..58b6343 100644 (file)
@@ -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