Process Class Reference

The Process class is used to start external programs and to communicate with them. The Process class can start programs synchronously using Process.execute(), and asynchronously using {new Process(...).start()}.
  • stdout : String; Contains the data sent to stdout during the last call to Process.execute(). This property is read-only.

  • stderr : String; Contains the data sent to stderr during the last call to Process.execute(). This property is read-only.

  • execute( command : String, stdin : String ); Executes command synchronously and passes stdin to its standard input if specified. When the program ends its output is accessible through Process.stdout and Process.stderr. command can contain both the program and command line arguments, e.g. "ls -la" . The function returns the executed commands return code on exit.

  • execute( command : String[], stdin : String ); Same as above, except that command is an array of strings, where the first item is the name of the program and the following items are command line arguments. This version is useful if you have arguments that contain spaces or other characters that would need to be quoted if you just passed a single string command line, since it takes care of the quoting for you. Note that if the user passes an array of only one element this function behaves like the overload taking a string, thus splitting it into "command" and "arguments". \ executeNoSplit( command : String[], stdin : String ); Same as above, except that command is an array of strings, where the first item is the name of the program and the following items are command line arguments. This version is useful if you have arguments that contain spaces or other characters that would need to be quoted if you just passed a single string command line, since it takes care of the quoting for you. This function never splits the first argument, regardless of the number of strings in the command array.

  • Process(); Creates a Process object without specifying the program or any arguments. This does not start a process.

  • Process( command : String ); Creates a Process object that will execute command. This does not start the process.

  • Process( command : String[] ); Same as above, except that command is an array of strings, where the first item is the name of the program and the following items are command line arguments. This version is useful if you have arguments that contain spaces or other characters that would need to be quoted if you just passed a single string command line, since it takes care of the quoting for you.

  • arguments : String[]; Contains an array of strings where the first item is the program to execute and the following items are the command line arguments.

  • workingDirectory : String; Contains the working directory for the process.

  • running : Boolean; True if the process is currently running; otherwise false. This property is read-only.

  • exitStatus : Number; Contains the exitStatus of the program when it has finished. This property is read-only.

  • start( env : String[] ); Tries to run a process for the command and arguments that were specified with the argument property or that were specified in the constructor. The command is searched for in the path for executable programs; you can also use an absolute path in the command itself. If env is not specified, the process is started with the same environment as the starting process. If env is specified, then the values in the env stringlist are interpreted as environment setttings of the form VARIABLE=VALUE and the process is started with these environment settings. If the program could not be started, an exception is thrown.

  • launch( stdin : String, env : String[] ); Runs the process and writes the data stdin to the process's standard input. If all the data is written to standard input, standard input is closed. The command is searched for in the path for executable programs; you can also use an absolute path in the command itself. If env is unspecified, the process is started with the same environment as the starting process. If env is specified, then the values in the string list are interpreted as environment setttings of the form VARIABLE=VALUE and the process is started with these environment settings. If the program could not be started, an exception is thrown.

  • readStdout() : String; Reads what is currently available on the process's standard output.

  • readSterr() : String; Reads what is currently available on the process's standard error.

  • canReadLineStdout() : Boolean; Returns true if a line can be read from the process's standard output.

  • canReadLineStderr() : Boolean; Returns true if a line can be read from the process's standard error.

  • readLineStdout() : String; Reads one line of text from the process's standard output if available; otherwise returns an empty string.

  • readLineStderr() : String; Reads one line of text from the process's standard error if available; otherwise returns an empty string.

  • tryTerminate(); Asks the process to terminate. Processes can ignore this if they wish. If you want to be certain that the process really terminates, you can use kill() instead.

  • kill(); Terminates the process. This is not a safe way to end a process since the process will not be able to do any cleanup. tryTerminate() is safer, but processes can ignore tryTerminate().

  • writeToStdin( buffer : String ); Writes the data buffer to the process's standard input. The process may or may not read this data.

  • closeStdin(); Closes the process's standard input.