Prechádzať zdrojové kódy

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

Andy Li 9 rokov pred
rodič
commit
e9885a1a8e

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

@@ -37,9 +37,7 @@ class Process {
 	var p:Popen;
 
 	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.stderr = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stderr)));
 		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.Tuple;
 import python.Dict;
+import haxe.extern.EitherType;
 
 typedef PopenOptions = {
 	?bufsize : Int,
@@ -47,7 +48,7 @@ typedef PopenOptions = {
 @:pythonImport("subprocess", "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.executable = if (Reflect.hasField(o, "executable")) o.executable else null;