Browse Source

[lua] fix io process (address #8216)

Justin Donaldson 6 years ago
parent
commit
24b8830663
2 changed files with 13 additions and 9 deletions
  1. 13 7
      std/lua/_std/sys/io/Process.hx
  2. 0 2
      tests/sys/src/TestUnicode.hx

+ 13 - 7
std/lua/_std/sys/io/Process.hx

@@ -89,15 +89,22 @@ class Process {
 
 
 		var opt = {args: setArgs(cmd, args), stdio: stdio};
 		var opt = {args: setArgs(cmd, args), stdio: stdio};
 
 
-		var p:lua.lib.luv.Process.LuvSpawn;
-		p = lua.lib.luv.Process.spawn(_shell, opt, function(code:Int, signal:Signal) {
+		var p = lua.lib.luv.Process.spawn(_shell, opt, function(code:Int, signal:Signal) {
 			_code = code;
 			_code = code;
+			if (!_handle.is_closing()){
+			    _handle.close();
+            }
+            _stdin.shutdown(()->_stdin.close());
+            _stderr.shutdown(()->_stderr.close());
+            _stdout.shutdown(()->_stdout.close());
+
 		});
 		});
+		_handle = p.handle;
 
 
 		if (p.handle == null)
 		if (p.handle == null)
 			throw p.pid;
 			throw p.pid;
+
 		_pid = p.pid;
 		_pid = p.pid;
-		_handle = p.handle;
 	}
 	}
 
 
 	public function getPid():Int {
 	public function getPid():Int {
@@ -105,10 +112,9 @@ class Process {
 	}
 	}
 
 
 	public function close():Void {
 	public function close():Void {
-		stdout.close();
-		stdin.close();
-		stderr.close();
-		_handle.close();
+		if (!_handle.is_closing()){
+            _handle.close();
+        }
 	}
 	}
 
 
 	public function exitCode(block:Bool = true):Null<Int> {
 	public function exitCode(block:Bool = true):Null<Int> {

+ 0 - 2
tests/sys/src/TestUnicode.hx

@@ -326,10 +326,8 @@ class TestUnicode extends utest.Test {
 #if (hl || cpp) if (Sys.systemName() != "Windows") { #end // HL and C++ temporarily disabled (#8379)
 #if (hl || cpp) if (Sys.systemName() != "Windows") { #end // HL and C++ temporarily disabled (#8379)
 				// putEnv + getEnv
 				// putEnv + getEnv
 				assertUEquals(runUtility(["putEnv", "HAXE_TEST", '$i', mode, "getEnv", "HAXE_TEST"]).stdout, str + endLine);
 				assertUEquals(runUtility(["putEnv", "HAXE_TEST", '$i', mode, "getEnv", "HAXE_TEST"]).stdout, str + endLine);
-#if !lua // Lua disabled temporarily (#8216)
 				// putEnv + environment
 				// putEnv + environment
 				assertUEquals(runUtility(["putEnv", "HAXE_TEST", '$i', mode, "environment", "HAXE_TEST"]).stdout, str + endLine);
 				assertUEquals(runUtility(["putEnv", "HAXE_TEST", '$i', mode, "environment", "HAXE_TEST"]).stdout, str + endLine);
-#end
 #if (hl || cpp) } #end // HL and C++ temporarily disabled (#8379)
 #if (hl || cpp) } #end // HL and C++ temporarily disabled (#8379)
 				#end
 				#end
 			});
 			});