JDK-8013350 : ProcessBuilder execution for command with pipe fails.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7u21
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2013-04-26
  • Updated: 2014-11-17
  • Resolved: 2013-05-07
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.7.0_21

ADDITIONAL OS VERSION INFORMATION :
Windows 7 Professional 64 Bit
Service Pack 1

A DESCRIPTION OF THE PROBLEM :
The ProcessBuilder ignores a pipe symbol (>) in the DIR command.
The command  " cmd /c dir c: > c:/dir.txt "  should create the file c:/dir.txt.
Since jdk7u21 the file is not created. No exceptions are thrown.

REGRESSION.  Last worked in version 7u17

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and execute the specified source code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The file c:/dir.txt should be created.
ACTUAL -
No file created.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;

public class JavaTest {
public static void main(String[] args) {
try {
ProcessBuilder builder = new ProcessBuilder( " cmd " ,  " /c " ,  " dir " ,  " c: " ,  " > " ,  " c:/dir.txt " );
builder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
Comments
Duplicates JDK-8012453 bug in the part of undocumented IOException. In test implementation there is at least one error. To be short: the code ------------------- SOURCE BEGIN ------------------- try { ProcessBuilder builder = new ProcessBuilder( "cmd.exe" , "/C" , "dir c: > c:\\dir.txt" ); builder.start(); } catch (Exception e) { e.printStackTrace(); } ------------------- SOURCE END ------------------- works fine. The string ["dir c: > c:\\dir.txt"] is a single argument - the shell construction that need to be processed.
07-05-2013

The exception is thrown - that is the IllegalArgumentException exception. The IllegalArgumentException exception is not described for the call in Javadoc and it is a part of JDK-8012453 fix. Java does not support redirection from command line, please use redirectOutput method.
26-04-2013

This usage should never have worked, and doesn't work since 7u21 because the validation has been tightened up. The supported way to redirect the output is via the ProcessBuilder redirectOutput method.
26-04-2013