|
@@ -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);
|