|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
35 | 35 | * @requires !vm.musl
|
36 | 36 | * @requires vm.flagless
|
37 | 37 | * @library /test/lib
|
38 |
| - * @run main/othervm/native/timeout=300 Basic |
39 |
| - * @run main/othervm/native/timeout=300 -Djdk.lang.Process.launchMechanism=fork Basic |
| 38 | + * @run main/othervm/native/timeout=360 Basic |
| 39 | + * @run main/othervm/native/timeout=360 -Djdk.lang.Process.launchMechanism=fork Basic |
40 | 40 | * @author Martin Buchholz
|
41 | 41 | */
|
42 | 42 |
|
|
55 | 55 | import static java.lang.ProcessBuilder.Redirect.*;
|
56 | 56 |
|
57 | 57 | import java.io.*;
|
58 |
| -import java.lang.reflect.Field; |
59 | 58 | import java.nio.charset.Charset;
|
60 | 59 | import java.nio.file.Files;
|
61 | 60 | import java.nio.file.Path;
|
@@ -207,7 +206,7 @@ private static void compareLinesIgnoreCase(String lines1, String lines2) {
|
207 | 206 |
|
208 | 207 | private static final Runtime runtime = Runtime.getRuntime();
|
209 | 208 |
|
210 |
| - private static final String[] winEnvCommand = {"cmd.exe", "/c", "set"}; |
| 209 | + private static final String[] winEnvCommand = {"cmd.exe", "/d", "/c", "set"}; |
211 | 210 |
|
212 | 211 | private static String winEnvFilter(String env) {
|
213 | 212 | return env.replaceAll("\r", "")
|
@@ -1841,7 +1840,9 @@ public void doIt(Map<String,String> environ) {
|
1841 | 1840 | // Test Runtime.exec(...envp...) with envstrings without any `='
|
1842 | 1841 | //----------------------------------------------------------------
|
1843 | 1842 | try {
|
1844 |
| - String[] cmdp = {"echo"}; |
| 1843 | + // In Windows CMD (`cmd.exe`), `echo/` outputs a newline (i.e., an empty line). |
| 1844 | + // Wrapping it with `cmd.exe /c` ensures compatibility in both native Windows and Cygwin environments. |
| 1845 | + String[] cmdp = Windows.is() ? new String[]{"cmd.exe", "/c", "echo/"} : new String[]{"echo"}; |
1845 | 1846 | String[] envp = {"Hello", "World"}; // Yuck!
|
1846 | 1847 | Process p = Runtime.getRuntime().exec(cmdp, envp);
|
1847 | 1848 | equal(commandOutput(p), "\n");
|
|
0 commit comments