Popen.hx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C)2005-2017 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package python.lib.subprocess;
  23. import python.lib.io.BufferedReader;
  24. import python.lib.io.FileIO;
  25. import python.lib.io.TextIOBase;
  26. import python.lib.Subprocess.StartupInfo;
  27. import python.Tuple;
  28. import python.Dict;
  29. import haxe.extern.EitherType;
  30. typedef PopenOptions = {
  31. ?bufsize : Int,
  32. ?executable : String,
  33. ?stdin : Dynamic,
  34. ?stdout : Dynamic,
  35. ?stderr : Dynamic,
  36. ?preexec_fn : Void->Void,
  37. ?close_fds : Bool,
  38. ?shell : Bool,
  39. ?cwd : String,
  40. ?env : Dict<String, String>,
  41. ?universal_newlines : Bool,
  42. ?startupinfo : StartupInfo,
  43. ?creationflags : Int,
  44. }
  45. @:pythonImport("subprocess", "Popen")
  46. extern class Popen {
  47. public static inline function create (args:EitherType<String, Array<String>>, o:PopenOptions):Popen {
  48. o.bufsize = if (Reflect.hasField(o, "bufsize")) o.bufsize else 0;
  49. o.executable = if (Reflect.hasField(o, "executable")) o.executable else null;
  50. o.stdin = if (Reflect.hasField(o, "stdin")) o.stdin else null;
  51. o.stdout = if (Reflect.hasField(o, "stdout")) o.stdout else null;
  52. o.stderr = if (Reflect.hasField(o, "stderr")) o.stderr else null;
  53. o.preexec_fn = if (Reflect.hasField(o, "preexec_fn")) o.preexec_fn else null;
  54. o.close_fds = if (Reflect.hasField(o, "close_fds")) o.close_fds else null;
  55. o.shell = if (Reflect.hasField(o, "shell")) o.shell else null;
  56. o.cwd = if (Reflect.hasField(o, "cwd")) o.cwd else null;
  57. o.env = if (Reflect.hasField(o, "env")) o.env else null;
  58. o.universal_newlines = if (Reflect.hasField(o, "universal_newlines")) o.universal_newlines else null;
  59. o.startupinfo = if (Reflect.hasField(o, "startupinfo")) o.startupinfo else null;
  60. o.creationflags = if (Reflect.hasField(o, "creationflags")) o.creationflags else 0;
  61. if (std.Sys.systemName() == "Windows") {
  62. return new Popen(args, o.bufsize, o.executable, o.stdin, o.stdout, o.stderr, o.preexec_fn,
  63. o.close_fds, o.shell, o.cwd, o.env, o.universal_newlines, o.startupinfo, o.creationflags);
  64. } else {
  65. return new Popen(args, o.bufsize, o.executable, o.stdin, o.stdout, o.stderr, o.preexec_fn,
  66. o.close_fds, o.shell, o.cwd, o.env, o.universal_newlines, o.startupinfo);
  67. }
  68. }
  69. public function new (args:Array<String>, bufsize:Int=0, executable:String = null,
  70. stdin:Int = null, stdout:Int = null, stderr:Int=null, preexec_fn:Void->Void=null,
  71. close_fds:Bool=false, shell:Bool=false, cwd:String=null, env:Dict<String,String>=null,
  72. universal_newlines:Bool=false, startupinfo:StartupInfo=null, creationflags:Int=0):Void;
  73. public function kill ():Void;
  74. public function wait (?timeout:Null<Int>):Null<Int>;
  75. public function poll ():Null<Int>;
  76. public function terminate ():Void;
  77. public var stdout : FileIO;
  78. public var stderr : FileIO;
  79. public var stdin : FileIO;
  80. public var returncode : Int;
  81. public var pid:Int;
  82. public function communicate (input:Bytes = null, timeout:Null<Int> = null):Tuple2<Bytes, Bytes>;
  83. }