1 jls.loader.provide('jls.lang.ProcessBuilder');
  2 
  3 jls.loader.require('jls.lang.Process');
  4 
  5 jls.lang.ProcessBuilder = jls.lang.Class.create( /** @lends jls.lang.ProcessBuilder.prototype */
  6 {
  7     /**
  8      * Creates a process builder with the specified command and arguments with the specified environment and working directory.
  9      * 
 10      * @param {Array} cmdArray Array of strings specifying the command-line arguments. The first argument is the name of the executable file.
 11      * @param {Array} [envp] Array of key-values specifying the environment strings. If undefined, the new process inherits the environment of the parent process.
 12      * @constructs
 13      * @class This class is used to create OS processes.
 14      */
 15     initialize : function(cmdArray, envp) {
 16         this._no = undefined;
 17         this._cmdArray = cmdArray;
 18         this._envp = envp;
 19     },
 20     /**
 21      * Sets this process builder's working directory.
 22      * 
 23      * @param {jls.io.File} dir The working directory of the subprocess, or undefined if the subprocess should inherit the working directory of the current process.
 24      */
 25     setCurrentDirectory : function(dir) {
 26         if (! this._no) {
 27             this._no = new _native.core.ProcessAttr();
 28         }
 29         this._no.setCurrentDirectory(dir.getAbsolutePath());
 30     },
 31     /**
 32      * Sets this process builder's working directory.
 33      * 
 34      * @param {jls.io.FileDescriptor} fd The file descriptor to use for redirection.
 35      * @param {Number} stdio The standard IO to redirect.
 36      */
 37     setStdioRedirect : function(fd, stdio) {
 38         if (! this._no) {
 39             this._no = new _native.core.ProcessAttr();
 40         }
 41         fd.setInheritable(true);
 42         this._no.setStdioRedirect(fd.getFD(), stdio || jls.io.Pipe.StandardOutput);
 43     },
 44     /**
 45      * Starts a new process using the attributes of this process builder.
 46      * 
 47      * @returns {jls.lang.Process} A new Process for managing the subprocess.
 48      */
 49     start : function() {
 50         return new jls.lang.Process(this._cmdArray, this._envp, this._no);
 51     }
 52 });
 53 
 54 Object.extend(jls.lang.ProcessBuilder, /** @lends jls.lang.ProcessBuilder */
 55 {
 56     /**
 57      * Represents the standard output.
 58      * 
 59      * @type Number
 60      */
 61     StandardOutput : _native.core.ProcessAttr.StandardOutput,
 62     /**
 63      * Represents the standard error.
 64      * 
 65      * @type Number
 66      */
 67     StandardError : _native.core.ProcessAttr.StandardError,
 68     /**
 69      * Represents the standard input.
 70      * 
 71      * @type Number
 72      */
 73     StandardInput : _native.core.ProcessAttr.StandardInput
 74 });
 75 
 76