Popen.hx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package python.lib.subprocess;
  2. import python.lib.io.BufferedReader;
  3. import python.lib.io.TextIOBase;
  4. import python.lib.Subprocess.StartupInfo;
  5. import python.lib.Tuple;
  6. typedef PopenOptions = {
  7. ?bufsize : Int,
  8. ?executable : String,
  9. ?stdin : Dynamic,
  10. ?stdout : Dynamic,
  11. ?stderr : Dynamic,
  12. ?preexec_fn : Void->Void,
  13. ?close_fds : Bool,
  14. ?shell : Bool,
  15. ?cwd : String,
  16. ?env : Dict<String, String>,
  17. ?universal_newlines : Bool,
  18. ?startupinfo : StartupInfo,
  19. ?creationflags : Int,
  20. }
  21. @:pythonImport("subprocess", "Popen")
  22. extern class Popen {
  23. public static inline function create (args:Array<String>, o:PopenOptions):Popen {
  24. o.bufsize = if (Reflect.hasField(o, "bufsize")) o.bufsize else 0;
  25. o.executable = if (Reflect.hasField(o, "executable")) o.executable else null;
  26. o.stdin = if (Reflect.hasField(o, "stdin")) o.stdin else null;
  27. o.stdout = if (Reflect.hasField(o, "stdout")) o.stdout else null;
  28. o.stderr = if (Reflect.hasField(o, "stderr")) o.stderr else null;
  29. o.preexec_fn = if (Reflect.hasField(o, "preexec_fn")) o.preexec_fn else null;
  30. o.close_fds = if (Reflect.hasField(o, "close_fds")) o.close_fds else null;
  31. o.shell = if (Reflect.hasField(o, "shell")) o.shell else null;
  32. o.cwd = if (Reflect.hasField(o, "cwd")) o.cwd else null;
  33. o.env = if (Reflect.hasField(o, "env")) o.env else null;
  34. o.universal_newlines = if (Reflect.hasField(o, "universal_newlines")) o.universal_newlines else null;
  35. o.startupinfo = if (Reflect.hasField(o, "startupinfo")) o.startupinfo else null;
  36. o.creationflags = if (Reflect.hasField(o, "creationflags")) o.creationflags else 0;
  37. if (std.Sys.systemName() == "Windows") {
  38. return new Popen(args, o.bufsize, o.executable, o.stdin, o.stdout, o.stderr, o.preexec_fn,
  39. o.close_fds, o.shell, o.cwd, o.env, o.universal_newlines, o.startupinfo, o.creationflags);
  40. } else {
  41. return new Popen(args, o.bufsize, o.executable, o.stdin, o.stdout, o.stderr, o.preexec_fn,
  42. o.close_fds, o.shell, o.cwd, o.env, o.universal_newlines, o.startupinfo);
  43. }
  44. }
  45. public function new (args:Array<String>, bufsize:Int=0, executable:String = null,
  46. stdin:Int = null, stdout:Int = null, stderr:Int=null, preexec_fn:Void->Void=null,
  47. close_fds:Bool=false, shell:Bool=false, cwd:String=null, env:Dict<String,String>=null,
  48. universal_newlines:Bool=false, startupinfo:StartupInfo=null, creationflags:Int=0):Void;
  49. public function kill ():Void;
  50. public function wait (?timeout:Null<Int>):Null<Int>;
  51. public function poll ():Null<Int>;
  52. public function terminate ():Void;
  53. public var stdout : BufferedReader;
  54. public var stderr : BufferedReader;
  55. public var stdin : BufferedReader;
  56. public var returncode : Int;
  57. public var pid:Int;
  58. public function communicate (input:Bytes = null, timeout:Null<Int> = null):Tup2<Bytes, Bytes>;
  59. }