1 /*
2 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
479 quoteString(executablePath),
480 cmd);
481 }
482
483 handle = create(cmdstr, envblock, path,
484 stdHandles, redirectErrorStream);
485 // Register a cleaning function to close the handle
486 final long local_handle = handle; // local to prevent capture of this
487 CleanerFactory.cleaner().register(this, () -> closeHandle(local_handle));
488
489 processHandle = ProcessHandleImpl.getInternal(getProcessId0(handle));
490
491 java.security.AccessController.doPrivileged(
492 new java.security.PrivilegedAction<Void>() {
493 public Void run() {
494 if (stdHandles[0] == -1L)
495 stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE;
496 else {
497 FileDescriptor stdin_fd = new FileDescriptor();
498 fdAccess.setHandle(stdin_fd, stdHandles[0]);
499 stdin_stream = new BufferedOutputStream(
500 new FileOutputStream(stdin_fd));
501 }
502
503 if (stdHandles[1] == -1L || forceNullOutputStream)
504 stdout_stream = ProcessBuilder.NullInputStream.INSTANCE;
505 else {
506 FileDescriptor stdout_fd = new FileDescriptor();
507 fdAccess.setHandle(stdout_fd, stdHandles[1]);
508 stdout_stream = new BufferedInputStream(
509 new PipeInputStream(stdout_fd));
510 }
511
512 if (stdHandles[2] == -1L)
513 stderr_stream = ProcessBuilder.NullInputStream.INSTANCE;
514 else {
515 FileDescriptor stderr_fd = new FileDescriptor();
516 fdAccess.setHandle(stderr_fd, stdHandles[2]);
517 stderr_stream = new PipeInputStream(stderr_fd);
518 }
519
520 return null; }});
521 }
522
523 public OutputStream getOutputStream() {
524 return stdin_stream;
525 }
526
527 public InputStream getInputStream() {
528 return stdout_stream;
529 }
530
531 public InputStream getErrorStream() {
532 return stderr_stream;
533 }
534
535 private static final int STILL_ACTIVE = getStillActive();
536 private static native int getStillActive();
|
1 /*
2 * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
479 quoteString(executablePath),
480 cmd);
481 }
482
483 handle = create(cmdstr, envblock, path,
484 stdHandles, redirectErrorStream);
485 // Register a cleaning function to close the handle
486 final long local_handle = handle; // local to prevent capture of this
487 CleanerFactory.cleaner().register(this, () -> closeHandle(local_handle));
488
489 processHandle = ProcessHandleImpl.getInternal(getProcessId0(handle));
490
491 java.security.AccessController.doPrivileged(
492 new java.security.PrivilegedAction<Void>() {
493 public Void run() {
494 if (stdHandles[0] == -1L)
495 stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE;
496 else {
497 FileDescriptor stdin_fd = new FileDescriptor();
498 fdAccess.setHandle(stdin_fd, stdHandles[0]);
499 fdAccess.registerCleanup(stdin_fd);
500 stdin_stream = new BufferedOutputStream(
501 new FileOutputStream(stdin_fd));
502 }
503
504 if (stdHandles[1] == -1L || forceNullOutputStream)
505 stdout_stream = ProcessBuilder.NullInputStream.INSTANCE;
506 else {
507 FileDescriptor stdout_fd = new FileDescriptor();
508 fdAccess.setHandle(stdout_fd, stdHandles[1]);
509 fdAccess.registerCleanup(stdout_fd);
510 stdout_stream = new BufferedInputStream(
511 new PipeInputStream(stdout_fd));
512 }
513
514 if (stdHandles[2] == -1L)
515 stderr_stream = ProcessBuilder.NullInputStream.INSTANCE;
516 else {
517 FileDescriptor stderr_fd = new FileDescriptor();
518 fdAccess.setHandle(stderr_fd, stdHandles[2]);
519 fdAccess.registerCleanup(stderr_fd);
520 stderr_stream = new PipeInputStream(stderr_fd);
521 }
522
523 return null; }});
524 }
525
526 public OutputStream getOutputStream() {
527 return stdin_stream;
528 }
529
530 public InputStream getInputStream() {
531 return stdout_stream;
532 }
533
534 public InputStream getErrorStream() {
535 return stderr_stream;
536 }
537
538 private static final int STILL_ACTIVE = getStillActive();
539 private static native int getStillActive();
|