ADDITIONAL SYSTEM INFORMATION :
Tested on Oracle JDK build 17.0.1+12-LTS-3 on Windows, also affects OpenJDK build 19+36-2238 on Windows/Linux
A DESCRIPTION OF THE PROBLEM :
ProcessBuilder with inheritIO does run in same way under jshell compared with java. The stdout, stderr streams are supposed to be inherited and output from the sub-process should appear in the console.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run jshell and define class in the source code sample below, run the main without arguments as
jshell> JShellProcessBuilder.main();
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using java, the output on Windows is a directory listing of "dir" followed by:
Run: [cmd.exe, /c, dir] => 0
Using java, the output on Linux is a directory listing of "ls" followed by:
Run: [bash, -c, ls] => 0
ACTUAL -
Using jshell, the output on Windows does not print the standard output of "dir"
Using jshell, the output on Linux does not print the standard output of "ls"
---------- BEGIN SOURCE ----------
public class JShellProcessBuilder {
// jshell> JShellProcessBuilder.main()
public static void main(String... args) throws InterruptedException, IOException {
String [] cmd = System.getProperty("os.name").startsWith("Windows")
? new String[] {"cmd.exe", "/c", "dir"}
: new String[] {"bash", "-c", "ls" };
System.out.println("Run: "+Arrays.toString(cmd)+" => "+new ProcessBuilder(cmd).inheritIO().start().waitFor());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Avoid ProcessBuilder.inheritIO() and redirectXXX(ProcessBuilder.Redirect.INHERIT) calls, replace with redirectXXX(File) or consume the STDOUT/ERR streams in separate threads.
FREQUENCY : always
Tested on Oracle JDK build 17.0.1+12-LTS-3 on Windows, also affects OpenJDK build 19+36-2238 on Windows/Linux
A DESCRIPTION OF THE PROBLEM :
ProcessBuilder with inheritIO does run in same way under jshell compared with java. The stdout, stderr streams are supposed to be inherited and output from the sub-process should appear in the console.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run jshell and define class in the source code sample below, run the main without arguments as
jshell> JShellProcessBuilder.main();
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using java, the output on Windows is a directory listing of "dir" followed by:
Run: [cmd.exe, /c, dir] => 0
Using java, the output on Linux is a directory listing of "ls" followed by:
Run: [bash, -c, ls] => 0
ACTUAL -
Using jshell, the output on Windows does not print the standard output of "dir"
Using jshell, the output on Linux does not print the standard output of "ls"
---------- BEGIN SOURCE ----------
public class JShellProcessBuilder {
// jshell> JShellProcessBuilder.main()
public static void main(String... args) throws InterruptedException, IOException {
String [] cmd = System.getProperty("os.name").startsWith("Windows")
? new String[] {"cmd.exe", "/c", "dir"}
: new String[] {"bash", "-c", "ls" };
System.out.println("Run: "+Arrays.toString(cmd)+" => "+new ProcessBuilder(cmd).inheritIO().start().waitFor());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Avoid ProcessBuilder.inheritIO() and redirectXXX(ProcessBuilder.Redirect.INHERIT) calls, replace with redirectXXX(File) or consume the STDOUT/ERR streams in separate threads.
FREQUENCY : always