< prev index next >

src/java.base/share/classes/java/lang/ProcessBuilder.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.io.File;
  29 import java.io.FileDescriptor;
  30 import java.io.IOException;
  31 import java.io.InputStream;
  32 import java.io.OutputStream;
  33 import java.nio.channels.Pipe;
  34 import java.util.Arrays;
  35 import java.util.ArrayList;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.security.AccessController;
  39 import java.security.PrivilegedAction;
  40 /**
  41  * This class is used to create operating system processes.
  42  *
  43  * <p>Each {@code ProcessBuilder} instance manages a collection
  44  * of process attributes.  The {@link #start()} method creates a new
  45  * {@link Process} instance with those attributes.  The {@link
  46  * #start()} method can be invoked repeatedly from the same instance
  47  * to create new subprocesses with identical or related attributes.
  48  * <p>
  49  * The {@link #startPipeline startPipeline} method can be invoked to create
  50  * a pipeline of new processes that send the output of each process
  51  * directly to the next process.  Each process has the attributes of
  52  * its respective ProcessBuilder.
  53  *
  54  * <p>Each process builder manages these process attributes:
  55  *
  56  * <ul>
  57  *
  58  * <li>a <i>command</i>, a list of strings which signifies the
  59  * external program file to be invoked and its arguments, if any.


 451      * Each {@code Redirect} instance is one of the following:
 452      *
 453      * <ul>
 454      * <li>the special value {@link #PIPE Redirect.PIPE}
 455      * <li>the special value {@link #INHERIT Redirect.INHERIT}
 456      * <li>the special value {@link #DISCARD Redirect.DISCARD}
 457      * <li>a redirection to read from a file, created by an invocation of
 458      *     {@link Redirect#from Redirect.from(File)}
 459      * <li>a redirection to write to a file,  created by an invocation of
 460      *     {@link Redirect#to Redirect.to(File)}
 461      * <li>a redirection to append to a file, created by an invocation of
 462      *     {@link Redirect#appendTo Redirect.appendTo(File)}
 463      * </ul>
 464      *
 465      * <p>Each of the above categories has an associated unique
 466      * {@link Type Type}.
 467      *
 468      * @since 1.7
 469      */
 470     public abstract static class Redirect {
 471         private static final File NULL_FILE = AccessController.doPrivileged(
 472                 (PrivilegedAction<File>) () -> {
 473                     return new File((System.getProperty("os.name")
 474                             .startsWith("Windows") ? "NUL" : "/dev/null"));
 475                 }
 476         );
 477 
 478         /**
 479          * The type of a {@link Redirect}.
 480          */
 481         public enum Type {
 482             /**
 483              * The type of {@link Redirect#PIPE Redirect.PIPE}.
 484              */
 485             PIPE,
 486 
 487             /**
 488              * The type of {@link Redirect#INHERIT Redirect.INHERIT}.
 489              */
 490             INHERIT,
 491 
 492             /**
 493              * The type of redirects returned from
 494              * {@link Redirect#from Redirect.from(File)}.
 495              */




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.io.File;
  29 import java.io.FileDescriptor;
  30 import java.io.IOException;
  31 import java.io.InputStream;
  32 import java.io.OutputStream;

  33 import java.util.Arrays;
  34 import java.util.ArrayList;
  35 import java.util.List;
  36 import java.util.Map;
  37 import sun.security.action.GetPropertyAction;
  38 
  39 /**
  40  * This class is used to create operating system processes.
  41  *
  42  * <p>Each {@code ProcessBuilder} instance manages a collection
  43  * of process attributes.  The {@link #start()} method creates a new
  44  * {@link Process} instance with those attributes.  The {@link
  45  * #start()} method can be invoked repeatedly from the same instance
  46  * to create new subprocesses with identical or related attributes.
  47  * <p>
  48  * The {@link #startPipeline startPipeline} method can be invoked to create
  49  * a pipeline of new processes that send the output of each process
  50  * directly to the next process.  Each process has the attributes of
  51  * its respective ProcessBuilder.
  52  *
  53  * <p>Each process builder manages these process attributes:
  54  *
  55  * <ul>
  56  *
  57  * <li>a <i>command</i>, a list of strings which signifies the
  58  * external program file to be invoked and its arguments, if any.


 450      * Each {@code Redirect} instance is one of the following:
 451      *
 452      * <ul>
 453      * <li>the special value {@link #PIPE Redirect.PIPE}
 454      * <li>the special value {@link #INHERIT Redirect.INHERIT}
 455      * <li>the special value {@link #DISCARD Redirect.DISCARD}
 456      * <li>a redirection to read from a file, created by an invocation of
 457      *     {@link Redirect#from Redirect.from(File)}
 458      * <li>a redirection to write to a file,  created by an invocation of
 459      *     {@link Redirect#to Redirect.to(File)}
 460      * <li>a redirection to append to a file, created by an invocation of
 461      *     {@link Redirect#appendTo Redirect.appendTo(File)}
 462      * </ul>
 463      *
 464      * <p>Each of the above categories has an associated unique
 465      * {@link Type Type}.
 466      *
 467      * @since 1.7
 468      */
 469     public abstract static class Redirect {
 470         private static final File NULL_FILE = new File(
 471                 (GetPropertyAction.getProperty("os.name")
 472                         .startsWith("Windows") ? "NUL" : "/dev/null")


 473         );
 474 
 475         /**
 476          * The type of a {@link Redirect}.
 477          */
 478         public enum Type {
 479             /**
 480              * The type of {@link Redirect#PIPE Redirect.PIPE}.
 481              */
 482             PIPE,
 483 
 484             /**
 485              * The type of {@link Redirect#INHERIT Redirect.INHERIT}.
 486              */
 487             INHERIT,
 488 
 489             /**
 490              * The type of redirects returned from
 491              * {@link Redirect#from Redirect.from(File)}.
 492              */


< prev index next >