Sys.hx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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):String;
  30. extern static public function putEnv(s:String, v: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 public function cpuTime():Float;
  61. extern static public function programPath():String;
  62. extern static public function getChar(echo:Bool):Int;
  63. extern static public function stdin():haxe.io.Input;
  64. extern static public function stdout():haxe.io.Output;
  65. extern static public function stderr():haxe.io.Output;
  66. static function __init__():Void {
  67. // This nonsense causes the classes to be loaded. Otherwise they might not make
  68. // it into the interpreter, and then stderr() et. al. don't work.
  69. var _ = (null : sys.io.FileOutput);
  70. var _ = (null : sys.io.FileInput);
  71. }
  72. }