Process.hx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 sys.io;
  23. extern class Process {
  24. /**
  25. Standard output. The output stream where a process writes its output data.
  26. **/
  27. var stdout(default, null):haxe.io.Input;
  28. /**
  29. Standard error. The output stream to output error messages or diagnostics.
  30. **/
  31. var stderr(default, null):haxe.io.Input;
  32. /**
  33. Standard input. The stream data going into a process.
  34. **/
  35. var stdin(default, null):haxe.io.Output;
  36. /**
  37. Construct a `Process` object, which run the given command immediately.
  38. Command arguments can be passed in two ways: 1. using `args`, 2. appending to `cmd` and leaving `args` as `null`.
  39. 1. When using `args` to pass command arguments, each argument will be automatically quoted, and shell meta-characters will be escaped if needed.
  40. `cmd` should be an executable name that can be located in the `PATH` environment variable, or a path to an executable.
  41. 2. When `args` is not given or is `null`, command arguments can be appended to `cmd`. No automatic quoting/escaping will be performed. `cmd` should be formatted exactly as it would be when typed at the command line.
  42. It can run executables, as well as shell commands that are not executables (e.g. on Windows: `dir`, `cd`, `echo` etc).
  43. `detached` allows the created process to be standalone. You cannot communicate with it but you can look at its exit code. Not supported on php.
  44. `close()` should be called when the `Process` is no longer used.
  45. **/
  46. function new(cmd:String, ?args:Array<String>, ?detached:Bool):Void;
  47. /**
  48. Return the process ID.
  49. **/
  50. function getPid():Int;
  51. /**
  52. Query the exit code of the process.
  53. If `block` is true or not specified, it will block until the process terminates.
  54. If `block` is false, it will return either the process exit code if it's already terminated or null if it's still running.
  55. If the process has already exited, return the exit code immediately.
  56. **/
  57. function exitCode(block:Bool = true):Null<Int>;
  58. /**
  59. Close the process handle and release the associated resources.
  60. All `Process` fields should not be used after `close()` is called.
  61. **/
  62. function close():Void;
  63. /**
  64. Kill the process.
  65. **/
  66. function kill():Void;
  67. }