Sys.hx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /**
  23. This class gives you access to many base functionalities of system platforms. Looks in `sys` sub packages for more system APIs.
  24. **/
  25. @:require(sys)
  26. extern class Sys {
  27. /**
  28. Print any value on the standard output.
  29. **/
  30. static function print( v : Dynamic ) : Void;
  31. /**
  32. Print any value on the standard output, followed by a newline.
  33. **/
  34. static function println( v : Dynamic ) : Void;
  35. /**
  36. Returns all the arguments that were passed by the command line.
  37. **/
  38. static function args() : Array<String>;
  39. /**
  40. Returns the value of the given environment variable.
  41. **/
  42. static function getEnv( s : String ) : String;
  43. /**
  44. Set the value of the given environment variable.
  45. **/
  46. static function putEnv( s : String, v : String ) : Void;
  47. /**
  48. Returns all environment variables.
  49. **/
  50. static function environment() : Map<String,String>;
  51. /**
  52. Suspend the current execution for the given time (in seconds).
  53. **/
  54. static function sleep( seconds : Float ) : Void;
  55. /**
  56. Change the current time locale, which will affect `DateTools.format` date formating.
  57. Returns true if the locale was successfully changed
  58. **/
  59. static function setTimeLocale( loc : String ) : Bool;
  60. /**
  61. Get the current working directory (usually the one in which the program was started)
  62. **/
  63. static function getCwd() : String;
  64. /**
  65. Change the current working directory.
  66. **/
  67. static function setCwd( s : String ) : Void;
  68. /**
  69. Returns the name of the system you are running on. For instance :
  70. "Windows", "Linux", "BSD" and "Mac" depending on your desktop OS.
  71. **/
  72. static function systemName() : String;
  73. /**
  74. Run the given command. The command output will be printed on the same output as the current process.
  75. The current process will block until the command terminates and it will return the command result (0 if there was no error).
  76. Command arguments can be passed in two ways: 1. using `args`, 2. appending to `cmd` and leaving `args` as `null`.
  77. 1. When using `args` to pass command arguments, each argument will be automatically quoted, and shell meta-characters will be escaped if needed.
  78. `cmd` should be an executable name that can be located in the `PATH` environment variable, or a path to an executable.
  79. 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.
  80. It can run executables, as well as shell commands that are not executables (e.g. on Windows: `dir`, `cd`, `echo` etc).
  81. Read the `sys.io.Process` api for a more complete way to start background processes.
  82. **/
  83. static function command( cmd : String, ?args : Array<String> ) : Int;
  84. /**
  85. Exit the current process with the given error code.
  86. **/
  87. static function exit( code : Int ) : Void;
  88. /**
  89. Gives the most precise timestamp value (in seconds).
  90. **/
  91. static function time() : Float;
  92. /**
  93. Gives the most precise timestamp value (in seconds) but only account for the actual time spent running on the CPU for the current thread/process.
  94. **/
  95. static function cpuTime() : Float;
  96. /**
  97. Returns the path to the current executable that we are running.
  98. **/
  99. @:deprecated("Use programPath instead") static function executablePath() : String;
  100. /**
  101. Returns the absolute path to the current program file that we are running.
  102. Concretely, for an executable binary, it returns the path to the binary.
  103. For a script (e.g. a PHP file), it returns the path to the script.
  104. **/
  105. static function programPath() : String;
  106. /**
  107. Read a single input character from the standard input and returns it. Setting `echo` to true will also display it on the output.
  108. **/
  109. static function getChar( echo : Bool ) : Int;
  110. /**
  111. Returns the process standard input, from which you can read what user enters. Usually it will block until the user send a full input line. See `getChar` for an alternative.
  112. **/
  113. static function stdin() : haxe.io.Input;
  114. /**
  115. Returns the process standard output on which you can write.
  116. **/
  117. static function stdout() : haxe.io.Output;
  118. /**
  119. Returns the process standard error on which you can write.
  120. **/
  121. static function stderr() : haxe.io.Output;
  122. }