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 + "012345678901234567890123456789012345678900123456789"); 34 35 ProcessBuilder pb = new ProcessBuilder("hostname.exe"); 36 pb.redirectOutput(Redirect.appendTo(longFileName)); 37 Process p = pb.start(); 38 p.waitFor(); 39 40 if (longFileName.exists()) { 41 System.out.println("OK"); 42 } else { 43 throw new RuntimeException("Test failed."); 44 } 45 46 } finally { 47 longFileName.delete(); 48 dir2.delete(); 49 } 50 51 } 52 53 }