Popen.hx 2.5 KB

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