浏览代码

[python] support calling sys.io.Process with raw cmd string (when args is null)

Andy Li 9 年之前
父节点
当前提交
e9885a1a8e
共有 2 个文件被更改,包括 3 次插入4 次删除
  1. 1 3
      std/python/_std/sys/io/Process.hx
  2. 2 1
      std/python/lib/subprocess/Popen.hx

+ 1 - 3
std/python/_std/sys/io/Process.hx

@@ -37,9 +37,7 @@ class Process {
 	var p:Popen;
 	var p:Popen;
 
 
 	public function new( cmd : String, ?args : Array<String> ) : Void {
 	public function new( cmd : String, ?args : Array<String> ) : Void {
-
-		p = Popen.create([cmd].concat(args), { stdin : Subprocess.PIPE, stdout: Subprocess.PIPE, stderr : Subprocess.PIPE });
-
+		p = Popen.create(args == null ? cmd : [cmd].concat(args), { shell : args == null, stdin : Subprocess.PIPE, stdout: Subprocess.PIPE, stderr : Subprocess.PIPE });
 		this.stdout = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stdout)));
 		this.stdout = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stdout)));
 		this.stderr = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stderr)));
 		this.stderr = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stderr)));
 		this.stdin =  IoTools.createFileOutputFromText(new TextIOWrapper(new BufferedWriter(p.stdin)));
 		this.stdin =  IoTools.createFileOutputFromText(new TextIOWrapper(new BufferedWriter(p.stdin)));

+ 2 - 1
std/python/lib/subprocess/Popen.hx

@@ -27,6 +27,7 @@ import python.lib.io.TextIOBase;
 import python.lib.Subprocess.StartupInfo;
 import python.lib.Subprocess.StartupInfo;
 import python.Tuple;
 import python.Tuple;
 import python.Dict;
 import python.Dict;
+import haxe.extern.EitherType;
 
 
 typedef PopenOptions = {
 typedef PopenOptions = {
 	?bufsize : Int,
 	?bufsize : Int,
@@ -47,7 +48,7 @@ typedef PopenOptions = {
 @:pythonImport("subprocess", "Popen")
 @:pythonImport("subprocess", "Popen")
 extern class Popen {
 extern class Popen {
 
 
-	public static inline function create (args:Array<String>, o:PopenOptions):Popen {
+	public static inline function create (args:EitherType<String, Array<String>>, o:PopenOptions):Popen {
 
 
 		o.bufsize = if (Reflect.hasField(o, "bufsize")) o.bufsize else 0;
 		o.bufsize = if (Reflect.hasField(o, "bufsize")) o.bufsize else 0;
 		o.executable = if (Reflect.hasField(o, "executable")) o.executable else null;
 		o.executable = if (Reflect.hasField(o, "executable")) o.executable else null;