1  package frost.core
  2  
  3  ====================================================================================================
  4  Provides utility methods that interface with the operating environment.
  5  ====================================================================================================
  6  class System {
  7      ================================================================================================
  8      Represents a program launched by [System.exec].
  9      ================================================================================================
 10      class Process : Immutable {
 11          @private
 12          def pid:Int
 13  
 14          @private
 15          def stdin:Int
 16  
 17          @private
 18          def stdout:Int
 19  
 20          @private
 21          def stderr:Int
 22  
 23          ============================================================================================
 24          Returns an `OutputStream` which sends its output to the process' standard input stream.
 25          ============================================================================================
 26          @external(frostProcessStandardInput)
 27          method standardInput():OutputStream
 28  
 29          ============================================================================================
 30          Returns an `InputStream` which reads from the process' standard output stream.
 31          ============================================================================================
 32          @external(frostProcessStandardOutput)
 33          method standardOutput():InputStream
 34  
 35          ============================================================================================
 36          Returns an `InputStream` which reads from the process' standard error stream.
 37          ============================================================================================
 38          @external(frostProcessStandardError)
 39          method standardError():InputStream
 40  
 41          ============================================================================================
 42          Returns the process' exit code, or null if the process has not yet exited. The precise
 43          meaning of the exit code is defined by the program and operating environment, but typically
 44          an exit code of `0` indicates success and a non-zero exit code indicates an error.
 45          ============================================================================================
 46          @external(frostProcessExitCode)
 47          method exitCode():Int?
 48  
 49          ============================================================================================
 50          Waits for the process to finish and returns its exit code.
 51          ============================================================================================
 52          @external(frostProcessWaitFor)
 53          method waitFor():Int
 54  
 55          @private
 56          @external(frostProcessCleanup)
 57          method _cleanup()
 58          
 59          @override
 60          method cleanup() {
 61              _cleanup()
 62          }
 63      }
 64  
 65      @private
 66      init() {
 67      }
 68  
 69      ================================================================================================
 70      Returns the current working directory. As relative file paths are evaluated relative to this
 71      directory, changing the current working directory will break path evaluation and Frost therfore
 72      does not provide a means to do so.
 73      ================================================================================================
 74      @class
 75      @external(frostSystemWorkingDirectory)
 76      method workingDirectory():File
 77  
 78      ================================================================================================
 79      Returns a path to a directory suitable for storing temporary files. The operating environment
 80      may or may not automatically delete files written to this directory at some point after the
 81      program terminates. A well-behaved program will delete any temporary files it writes.
 82      ================================================================================================
 83      @class
 84      @external(frostSystemTemporaryDirectory)
 85      method temporaryDirectory():File
 86  
 87      ================================================================================================
 88      Causes the program to immediately stop running, returning the indicated exit code to the
 89      operating system. Generally an exit value of 0 is taken to mean a normal exit and a non-zero
 90      value is taken to mean an error occurred, but the interpretation of the exit codeis
 91      system-dependent. Cleanup methods are **not** run when an exit is forced in this fashion; among
 92      other things, this means that open files will not be properly flushed and closed, which may
 93      cause output to be incomplete.
 94      ================================================================================================
 95      @class
 96      @noReturn
 97      @external(frostSystemExit)
 98      method exit(status:Int)
 99  
100      ================================================================================================
101      Causes the program to perform an illegal operation which forces an abnormal exit.
102      ================================================================================================
103      @class
104      @noReturn
105      @external(frostSystemCrash)
106      method crash()
107  
108      ================================================================================================
109      Executes an external program with the given command line arguments. If `path` is just a filename
110      (meaning it does not contain any path separator characters), the system PATH environment
111      variable will be searched to find it.
112  
113      Returns the resulting process, or an error if it could not be created. Successfully creating the
114      process does not necessarily mean that the child program can actually be executed. If a
115      `Process` is returned, but the child program cannot not be successfully started, the resulting
116      process will exit immediately with a nonzero exit code, but no error will otherwise be reported.
117      ================================================================================================
118      @class
119      @external(frostSystemExec)
120      method exec(path:String, args:ListView<String>):Maybe<Process>
121  }