1 /* 2 * Copyright (c) 2016, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * JDK-8141209 : $EXEC should allow streaming 26 * 27 * @test 28 * @fork 29 * @option -scripting 30 * @run 31 */ 32 33 34 var System = Java.type("java.lang.System"); 35 var File = Java.type("java.io.File"); 36 var ByteArrayInputStream = Java.type("java.io.ByteArrayInputStream"); 37 var ByteArrayOutputStream = Java.type("java.io.ByteArrayOutputStream"); 38 39 var input = <<<EOD 40 There was an Old Man with a beard, 41 Who said, It is just as I feared! 42 Two Owls and a Hen, 43 Four Larks and a Wren, 44 Have all built their nests in my beard! 45 EOD 46 47 function tempFile() { 48 return File.createTempFile("JDK-8141209", ".txt").toString(); 49 } 50 51 `ls -l / | sed > ${tempFile()} -e '/^d/ d'` 52 53 $EXEC(["ls", "-l", "|", "sed", "-e", "/^d/ d", ">", tempFile()]) 54 55 var t1 = tempFile(); 56 57 $EXEC(<<<EOD) 58 ls -l >${t1} 59 sed <${t1} >${tempFile()} -e '/^d/ d' 60 EOD 61 62 $EXEC(<<<EOD, `ls -l`) 63 sed >${tempFile()} -e '/^d/ d' 64 EOD 65 66 var instream = new ByteArrayInputStream(input.getBytes()); 67 var outstream = new ByteArrayOutputStream(); 68 var errstream = new ByteArrayOutputStream(); 69 $EXEC("sed -e '/beard/ d'", instream, outstream, errstream); 70 var out = outstream.toString(); 71 var err = errstream.toString(); 72 73 instream = new ByteArrayInputStream(input.getBytes()); 74 $EXEC("sed -e '/beard/ d'", instream, System.out, System.err); 75 76 77 $EXEC(<<<EOD) 78 cd . 79 setenv TEMP 0 80 unsetenv TEMP 81 EOD 82 83 $ENV.JJS_THROW_ON_EXIT = "1"; 84 $ENV.JJS_TIMEOUT = "1000"; 85 $ENV.JJS_ECHO = "1"; 86 $ENV.JJS_INHERIT_IO = "1"; 87 88 $EXEC("echo hello world", instream); 89 90 91