ExecWithInput.java revision 2362
2362N/A * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @summary Ensure that piped input always works with exec'd processes 0N/A * This class demonstrates a regression in java1.4.1 in the handling of the 0N/A * Process OutputStream (exec'd process stdin). The subprocess completes 100% 0N/A * of the time in 1.4, but about only about 50% of the time under 1.4.1. Issue 0N/A * exists for client JVM, Linux Redhat 6.2 not sure about other variants of 0N/A * Linux or other OSes, or server JVM. 0N/A private static final int N =
200;
0N/A * Execute /bin/cat supplying two lines of input. cat should 0N/A * read the input lines and copy them to stdout. On completion, 0N/A * p.waitFor should return and the exit status is printed and this 0N/A * program exits. Under 1.4.1, cat sometimes gets stuck on a pipe 0N/A * read and never terminates. 0N/A //Process p = Runtime.getRuntime().exec(new String[] { CAT } ); 0N/A // create threads to handle I/O streams 0N/A // wait for process to exit 0N/A for (
int i =
0; i < N; i++)
0N/A * Handle IO. Thread is started in constructor. 0N/A while ((c = in.read()) != -1) { 0N/A // Note: in order to get an exec'd java process to 0N/A // see EOF on input, it is necessary to close stdin