Quellcode durchsuchen

fixes for hl sys

Nicolas Cannasse vor 8 Jahren
Ursprung
Commit
59bcabb7f1

+ 48 - 3
std/hl/_std/sys/io/Process.hx

@@ -50,7 +50,7 @@ private class Stdin extends haxe.io.Output {
 	}
 
 	@:hlNative("std","process_stdin_write") static function _stdin_write( p : ProcessHandle, bytes : hl.Bytes, pos : Int, len : Int ) : Int { return 0; }
-	@:hlNative("std","process_stdin_close") static function _stdin_close( p : ProcessHandle ) : Void { }
+	@:hlNative("std", "process_stdin_close") static function _stdin_close( p : ProcessHandle ) : Bool { return false; }
 
 }
 
@@ -89,9 +89,54 @@ private class Stdout extends haxe.io.Input {
 	var p : ProcessHandle;
 	public var stdout(default,null) : haxe.io.Input;
 	public var stderr(default,null) : haxe.io.Input;
-	public var stdin(default,null) : haxe.io.Output;
+	public var stdin(default, null) : haxe.io.Output;
+
+	static var isWin = Sys.systemName() == "Windows";
 
 	public function new( cmd : String, ?args : Array<String> ) : Void {
+		var runCmd = cmd;
+		if( isWin ) {
+			var b = new StringBuf();
+			if( args == null ) {
+				var exe = Sys.getEnv("COMSPEC");
+				if( exe == null ) exe = "cmd.exe";
+				b.add("\"");
+				b.add(exe);
+				b.add("\" /C \"");
+				b.add(cmd);
+				b.addChar('"'.code);
+			} else {
+				b.addChar('"'.code);
+				b.add(cmd);
+				b.addChar('"'.code);
+				for( a in args ) {
+					b.add(" \"");
+					var bsCount = 0;
+					for( i in 0...a.length ) {
+						switch( StringTools.fastCodeAt(a, i) ) {
+						case '"'.code:
+							for( i in 0...bsCount * 2 )
+								b.addChar('\\'.code);
+							bsCount = 0;
+							b.add("\\\"");
+						case '\\'.code:
+							bsCount++;
+						case c:
+							for( i in 0...bsCount )
+								b.addChar('\\'.code);
+							bsCount = 0;
+							b.addChar(c);
+						}
+					}
+					// Add remaining backslashes, if any.
+					for( i in 0...bsCount * 2 )
+						b.addChar('\\'.code);
+					b.addChar('"'.code);
+				}
+				args = null;
+			}
+			runCmd = b.toString();
+		}
 		@:privateAccess {
 			var aargs = null;
 			if( args != null ) {
@@ -99,7 +144,7 @@ private class Stdout extends haxe.io.Input {
 				for( i in 0...args.length )
 					aargs[i] = Sys.getPath(args[i]);
 			}
-			p = _run(Sys.getPath(cmd), aargs);
+			p = _run(Sys.getPath(runCmd), aargs);
 		}
 		if( p == null )
 			throw new Sys.SysError("Process creation failure : "+cmd);

+ 3 - 3
tests/sys/compile-hl.hxml

@@ -1,13 +1,13 @@
 compile-each.hxml
 -main Main
--hl bin/_main.c
+-hl bin/hl/sys.hl
 
 --next
 compile-each.hxml
 -main TestArguments
--cpp bin/_args.c
+-hl bin/hl/TestArguments.hl
 
 --next
 compile-each.hxml
 -main ExitCode
--cpp bin/_exit.c
+-hl bin/hl/ExitCode.hl

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

@@ -9,6 +9,8 @@ class ExitCode {
 	static public var bin:String =
 	#if neko
 		"bin/neko/ExitCode.n";
+	#elseif hl
+		"bin/hl/ExitCode.hl";
 	#elseif cpp
 		#if debug
 			"bin/cpp/ExitCode-debug";

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

@@ -66,6 +66,8 @@ class TestArguments extends haxe.unit.TestCase {
 	static public var bin:String =
 	#if neko
 		"bin/neko/TestArguments.n";
+	#elseif hl
+		"bin/hl/TestArguments.hl";
 	#elseif cpp
 		#if debug
 			"bin/cpp/TestArguments-debug";

+ 4 - 0
tests/sys/src/TestCommandBase.hx

@@ -36,6 +36,8 @@ class TestCommandBase extends haxe.unit.TestCase {
 				run(python.lib.Sys.executable, [bin].concat(args));
 			#elseif neko
 				run("neko", [bin].concat(args));
+			#elseif hl
+				run("hl", [bin].concat(args));
 			#elseif php
 				run(untyped __php__("defined('PHP_BINARY') ? PHP_BINARY : 'php'"), [bin].concat(args));
 			#elseif lua
@@ -121,6 +123,8 @@ class TestCommandBase extends haxe.unit.TestCase {
 					run(python.lib.Sys.executable, [bin].concat(args));
 				#elseif neko
 					run("neko", [bin].concat(args));
+				#elseif hl
+					run("hl", [bin].concat(args));
 				#elseif php
 					run(untyped __php__("defined('PHP_BINARY') ? PHP_BINARY : 'php'"), [bin].concat(args));
 				#elseif lua