Popen.hx 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C)2005-2019 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. 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, o.close_fds, o.shell, o.cwd, o.env,
  63. 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, o.close_fds, o.shell, o.cwd, o.env,
  66. o.universal_newlines, o.startupinfo);
  67. }
  68. }
  69. function new(args:Array<String>, bufsize:Int = 0, executable:String = null, stdin:Int = null, stdout:Int = null, stderr:Int = null,
  70. preexec_fn:Void->Void = null, close_fds:Bool = false, shell:Bool = false, cwd:String = null, env:Dict<String, String> = null,
  71. universal_newlines:Bool = false, startupinfo:StartupInfo = null, creationflags:Int = 0):Void;
  72. function kill():Void;
  73. function wait(?timeout:Int):Null<Int>;
  74. function poll():Null<Int>;
  75. function terminate():Void;
  76. var stdout:FileIO;
  77. var stderr:FileIO;
  78. var stdin:FileIO;
  79. var returncode:Int;
  80. var pid:Int;
  81. function communicate(input:Bytes = null, timeout:Null<Int> = null):Tuple2<Bytes, Bytes>;
  82. }