1 import java.io.File; 2 import java.lang.ProcessBuilder.Redirect; 3 import java.nio.file.Files; 4 import java.nio.file.Path; 5 import java.nio.file.Paths; 6 7 /* 8 * @test 9 * @bug 8072611 10 * @summary ProcessBuilder Redirect to file appending on Windows should work with long file names 11 * @author Thomas Stuefe 12 */ 13 public class RedirectWithLongFilename { 14 15 public static void main(String[] args) throws Exception { 16 17 // windows only 18 if (Basic.Unix.is()) { 19 return; 20 } 21 22 // Redirect ProcessBuilder output to a file whose pathlen is > 255. 23 Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir")); 24 File dir2 = null; 25 File longFileName = null; 26 27 try { 28 dir2 = Files.createTempDirectory(tmpDir, "RedirectWithLongFilename").toFile(); 29 dir2.mkdirs(); 30 longFileName = new File( 31 dir2, "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" 32 + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); 33 34 ProcessBuilder pb = new ProcessBuilder("hostname.exe"); 35 pb.redirectOutput(Redirect.appendTo(longFileName)); 36 Process p = pb.start(); 37 p.waitFor(); 38 39 if (!longFileName.exists()) { 40 throw new RuntimeException("Test failed."); 41 } 42 43 } finally { 44 longFileName.delete(); 45 dir2.delete(); 46 } 47 48 } 49 50 }