0N/A/*
3157N/A * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A */
0N/A
0N/A/*
1879N/A * @test
1879N/A * @bug 4156278
1879N/A * @summary Basic functional test for
1879N/A * Runtime.exec(String[] command, String[] env, File path) and
1879N/A * Runtime.exec(String command, String[] env, File path).
1879N/A *
1879N/A * @build SetCwd
1879N/A * @run shell setcwd.sh
1879N/A */
1879N/Aimport java.io.*;
1879N/A
1879N/Apublic class SetCwd {
1879N/A public static void testExec(String cmd, String[] cmdarray, boolean flag)
1879N/A throws Exception {
1879N/A File dir = new File(".");
1879N/A File[] files = dir.listFiles();
1879N/A String curDir = dir.getCanonicalPath();
1879N/A
4141N/A for (int i = 0; i < files.length; i++) {
4141N/A File f = files[i];
4141N/A if (f.isDirectory() && (new File(f, "SetCwd.class")).exists()) {
4141N/A String newDir = f.getCanonicalPath();
1879N/A // exec a new SetCwd in the sub directory
1879N/A Process p = null;
1879N/A if (flag) {
1879N/A p = Runtime.getRuntime().exec(cmd, null, f);
1879N/A } else {
1879N/A p = Runtime.getRuntime().exec(cmdarray, null, f);
1879N/A }
1879N/A
1879N/A BufferedReader in = new BufferedReader
1879N/A (new InputStreamReader(p.getInputStream()));
1879N/A // Read back output from child
1879N/A String s = in.readLine();
1879N/A if (!s.startsWith(newDir)) {
3863N/A throw new Exception("inconsistent directory after exec");
1879N/A }
1879N/A // Join on the child
0N/A p.waitFor();
0N/A }
0N/A }
0N/A System.out.println(curDir);
4535N/A }
375N/A
375N/A public static void main (String args[]) throws Exception {
375N/A String cmdarray[] = new String[2];
375N/A cmdarray[0] = System.getProperty("java.home") + File.separator +
375N/A "bin" + File.separator + "java";
4535N/A cmdarray[1] = "SetCwd";
4535N/A String cmd = cmdarray[0] + " " + cmdarray[1];
4535N/A // test the two new methods
4535N/A testExec(cmd, null, true);
4535N/A testExec(null, cmdarray, false);
4535N/A }
4535N/A}
4535N/A