0N/A/*
2362N/A * Copyright (c) 2003, 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 *
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
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4794652
0N/A * @summary Ensure that a command argument that contains a space and a final
0N/A * backslash is handled correctly
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/A
0N/Apublic class ArgWithSpaceAndFinalBackslash {
0N/A
0N/A private static String getJavaCommand() {
0N/A String javaHome = System.getProperty("java.home");
0N/A if (javaHome != null && javaHome.length() > 0)
0N/A return (javaHome
0N/A + File.separatorChar + "bin"
0N/A + File.separatorChar + "java");
0N/A else
0N/A return "java";
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A if (args.length > 0) {
0N/A System.err.println(args[0]);
0N/A return;
0N/A }
0N/A
0N/A String[] cmd = new String[5];
0N/A int i = 0;
0N/A cmd[i++] = getJavaCommand();
0N/A cmd[i++] = "-cp";
0N/A String cp = System.getProperty("test.classes");
0N/A if (cp == null)
0N/A cp = ".";
0N/A cmd[i++] = cp;
0N/A cmd[i++] = "ArgWithSpaceAndFinalBackslash";
0N/A cmd[i++] = "foo bar\\baz\\";
0N/A
0N/A Process process = Runtime.getRuntime().exec(cmd);
0N/A InputStream in = process.getErrorStream();
0N/A byte[] buf = new byte[1024];
0N/A int n = 0, d;
0N/A while ((d = in.read(buf, n, buf.length - n)) >= 0)
0N/A n += d;
0N/A String s = new String(buf, 0, n, "US-ASCII").trim();
0N/A if (!s.equals(cmd[i - 1]))
0N/A throw new Exception("Test failed: Got \"" + s
0N/A + "\", expected \"" + cmd[i - 1] + "\"");
0N/A }
0N/A
0N/A}