Popen.hx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.Types;
  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. extern class Popen {
  22. public static inline function create (args:Array<String>, o:PopenOptions):Popen {
  23. o.bufsize = if (Reflect.hasField(o, "bufsize")) o.bufsize else 0;
  24. o.executable = if (Reflect.hasField(o, "executable")) o.executable else null;
  25. o.stdin = if (Reflect.hasField(o, "stdin")) o.stdin else null;
  26. o.stdout = if (Reflect.hasField(o, "stdout")) o.stdout else null;
  27. o.stderr = if (Reflect.hasField(o, "stderr")) o.stderr else null;
  28. o.preexec_fn = if (Reflect.hasField(o, "preexec_fn")) o.preexec_fn else null;
  29. o.close_fds = if (Reflect.hasField(o, "close_fds")) o.close_fds else null;
  30. o.shell = if (Reflect.hasField(o, "shell")) o.shell else null;
  31. o.cwd = if (Reflect.hasField(o, "cwd")) o.cwd else null;
  32. o.env = if (Reflect.hasField(o, "env")) o.env else null;
  33. o.universal_newlines = if (Reflect.hasField(o, "universal_newlines")) o.universal_newlines else null;
  34. o.startupinfo = if (Reflect.hasField(o, "startupinfo")) o.startupinfo else null;
  35. o.creationflags = if (Reflect.hasField(o, "creationflags")) o.creationflags else 0;
  36. if (std.Sys.systemName() == "Windows") {
  37. return new Popen(args, o.bufsize, o.executable, o.stdin, o.stdout, o.stderr, o.preexec_fn,
  38. o.close_fds, o.shell, o.cwd, o.env, o.universal_newlines, o.startupinfo, o.creationflags);
  39. } else {
  40. return new Popen(args, o.bufsize, o.executable, o.stdin, o.stdout, o.stderr, o.preexec_fn,
  41. o.close_fds, o.shell, o.cwd, o.env, o.universal_newlines, o.startupinfo);
  42. }
  43. }
  44. public function new (args:Array<String>, bufsize:Int=0, executable:String = null,
  45. stdin:Int = null, stdout:Int = null, stderr:Int=null, preexec_fn:Void->Void=null,
  46. close_fds:Bool=false, shell:Bool=false, cwd:String=null, env:Dict<String,String>=null,
  47. universal_newlines:Bool=false, startupinfo:StartupInfo=null, creationflags:Int=0):Void;
  48. public function kill ():Void;
  49. public function wait (?timeout:Null<Int>):Null<Int>;
  50. public function poll ():Null<Int>;
  51. public function terminate ():Void;
  52. public var stdout : BufferedReader;
  53. public var stderr : BufferedReader;
  54. public var stdin : BufferedReader;
  55. public var returncode : Int;
  56. public var pid:Int;
  57. public function communicate (input:Bytes = null, timeout:Null<Int> = null):Tup2<Bytes, Bytes>;
  58. static function __init__ ():Void
  59. {
  60. python.Syntax.importFromAs("subprocess", "Popen", "python.lib.subprocess.Popen");
  61. }
  62. }