Sys.hx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import haxe.SysTools;
  23. @:require(sys)
  24. @:coreApi
  25. class Sys {
  26. extern static public function print(v:Dynamic):Void;
  27. extern static public function println(v:Dynamic):Void;
  28. extern static public function args():Array<String>;
  29. extern static public function getEnv(s:String):Null<String>;
  30. extern static public function putEnv(s:String, v:Null<String>):Void;
  31. extern static public function environment():Map<String, String>;
  32. extern static public function sleep(seconds:Float):Void;
  33. extern static public function setTimeLocale(loc:String):Bool;
  34. extern static public function getCwd():String;
  35. extern static public function setCwd(s:String):Void;
  36. extern static public function systemName():String;
  37. extern static function _command(cmd:String):Int;
  38. static public function command(cmd:String, ?args:Array<String>):Int {
  39. if (args == null) {
  40. return _command(cmd);
  41. } else {
  42. switch (systemName()) {
  43. case "Windows":
  44. cmd = [
  45. for (a in [StringTools.replace(cmd, "/", "\\")].concat(args))
  46. SysTools.quoteWinArg(a, true)
  47. ].join(" ");
  48. return _command(cmd);
  49. case _:
  50. cmd = [cmd].concat(args).map(SysTools.quoteUnixArg).join(" ");
  51. return _command(cmd);
  52. }
  53. }
  54. }
  55. static public function executablePath():String {
  56. return programPath();
  57. }
  58. extern static public function exit(code:Int):Void;
  59. extern static public function time():Float;
  60. extern static function timestamp_ms():haxe.Int64;
  61. extern static public function cpuTime():Float;
  62. extern static public function programPath():String;
  63. extern static public function getChar(echo:Bool):Int;
  64. extern static public function stdin():haxe.io.Input;
  65. extern static public function stdout():haxe.io.Output;
  66. extern static public function stderr():haxe.io.Output;
  67. static function __init__():Void {
  68. // This nonsense causes the classes to be loaded. Otherwise they might not make
  69. // it into the interpreter, and then stderr() et. al. don't work.
  70. var _ = (null : sys.io.FileOutput);
  71. var _ = (null : sys.io.FileInput);
  72. }
  73. }