< prev index next >

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

Print this page




1234      *         <li>its
1235      *         {@link SecurityManager#checkExec checkExec}
1236      *         method doesn't allow creation of the subprocess, or
1237      *         <li>the standard input to the subprocess was
1238      *         {@linkplain #redirectInput redirected from a file}
1239      *         and the security manager's
1240      *         {@link SecurityManager#checkRead(String) checkRead} method
1241      *         denies read access to the file, or
1242      *         <li>the standard output or standard error of the
1243      *         subprocess was
1244      *         {@linkplain #redirectOutput redirected to a file}
1245      *         and the security manager's
1246      *         {@link SecurityManager#checkWrite(String) checkWrite} method
1247      *         denies write access to the file
1248      *         </ul>
1249      *
1250      * @throws  UnsupportedOperationException
1251      *          If the operating system does not support the creation of processes
1252      *
1253      * @throws IOException if an I/O error occurs

1254      */
1255     public static List<Process> startPipeline(List<ProcessBuilder> builders) throws IOException {
1256         // Accumulate and check the builders
1257         final int numBuilders = builders.size();
1258         List<Process> processes = new ArrayList<>(numBuilders);
1259         try {
1260             Redirect prevOutput = null;
1261             for (int index = 0; index < builders.size(); index++) {
1262                 ProcessBuilder builder = builders.get(index);
1263                 Redirect[] redirects = builder.redirects();
1264                 if (index > 0) {
1265                     // check the current Builder to see if it can take input from the previous
1266                     if (builder.redirectInput() != Redirect.PIPE) {
1267                         throw new IllegalArgumentException("builder redirectInput()" +
1268                                 " must be PIPE except for the first builder: "
1269                                 + builder.redirectInput());
1270                     }
1271                     redirects[0] = prevOutput;
1272                 }
1273                 if (index < numBuilders - 1) {




1234      *         <li>its
1235      *         {@link SecurityManager#checkExec checkExec}
1236      *         method doesn't allow creation of the subprocess, or
1237      *         <li>the standard input to the subprocess was
1238      *         {@linkplain #redirectInput redirected from a file}
1239      *         and the security manager's
1240      *         {@link SecurityManager#checkRead(String) checkRead} method
1241      *         denies read access to the file, or
1242      *         <li>the standard output or standard error of the
1243      *         subprocess was
1244      *         {@linkplain #redirectOutput redirected to a file}
1245      *         and the security manager's
1246      *         {@link SecurityManager#checkWrite(String) checkWrite} method
1247      *         denies write access to the file
1248      *         </ul>
1249      *
1250      * @throws  UnsupportedOperationException
1251      *          If the operating system does not support the creation of processes
1252      *
1253      * @throws IOException if an I/O error occurs
1254      * @since 9
1255      */
1256     public static List<Process> startPipeline(List<ProcessBuilder> builders) throws IOException {
1257         // Accumulate and check the builders
1258         final int numBuilders = builders.size();
1259         List<Process> processes = new ArrayList<>(numBuilders);
1260         try {
1261             Redirect prevOutput = null;
1262             for (int index = 0; index < builders.size(); index++) {
1263                 ProcessBuilder builder = builders.get(index);
1264                 Redirect[] redirects = builder.redirects();
1265                 if (index > 0) {
1266                     // check the current Builder to see if it can take input from the previous
1267                     if (builder.redirectInput() != Redirect.PIPE) {
1268                         throw new IllegalArgumentException("builder redirectInput()" +
1269                                 " must be PIPE except for the first builder: "
1270                                 + builder.redirectInput());
1271                     }
1272                     redirects[0] = prevOutput;
1273                 }
1274                 if (index < numBuilders - 1) {


< prev index next >