Hi, I'm trying to use ProcessBuilder to execute cygwin programs. ProcessBuilder is a Java API to run command lines. The problem I'm dealing with is that redirecting the stdout (or stderr) of a cygwin program to a file in append mode doesn't work. The file is not written. If I do the same with a normal windows program (not a cygwin one), it works. So it seems to be a cygwin related issue. If I redirect the stdout of the cygwin program to a file in write mode (instead of append mode), it does work too. Here's the groovy code I've used for testing: ///////////////////// dir = "C:\\\\pbtest\\\\"; logFile = dir + "foo.txt"; ProcessBuilder pb = new ProcessBuilder() .command("sh", "writer.sh") .directory(new File(dir)); // redirect stdout to a file in write mode //pb.redirectOutput(ProcessBuilder.Redirect.to(new File(logFile))); // redirect stdout to a file in append mode pb.redirectOutput(ProcessBuilder.Redirect.appendTo(new File(logFile))); pb.start(); ///////////////////// Where the script writer.sh just echoes a line on stdout. I've used "Process Monitor" to trace the accesses that are made to foo.txt both in the "append" and in the "write" cases. I've attached the two trace files to this mail. You'll notice that in the "append" case, sh doesn't even do the "WriteFile" call. The other difference between the two traces is the option list java is passing to the "CreateFile" call: In the "write" case: Desired Access: Generic Write, Read Attributes, Disposition: OverwriteIf
In the "append" case: Desired Access: Append Data/Add Subdirectory/Create Pipe Instance, Write EA, Read Attributes, Write Attributes, Read Control, Synchronize, Disposition: OpenIf NB: I'm running cygwin 1.7.32 (32-bit) on Windows 7 (64-bit). The Java version is 1.7.0_40. Regards, Pierre
16:02:51,0072167 java.exe 5612 CreateFile C:\pbtest\foo.txt SUCCESS Desired Access: Append Data/Add Subdirectory/Create Pipe Instance, Write EA, Read Attributes, Write Attributes, Read Control, Synchronize, Disposition: OpenIf, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Opened 16:02:51,0952435 sh.exe 3192 DeviceIoControl C:\pbtest\foo.txt INVALID PARAMETER Control: 0x1b0050 (Device:0x1b Function:20 Method: 0) 16:02:51,0952795 sh.exe 3192 QueryNameInformationFile C:\pbtest\foo.txt SUCCESS Name: \pbtest\foo.txt 16:02:51,0969548 sh.exe 3192 CreateFile C:\pbtest\foo.txt SUCCESS Desired Access: Read EA, Read Attributes, Read Control, Disposition: Open, Options: Open For Backup, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 16:02:51,0970670 sh.exe 3192 QueryInformationVolume C:\pbtest\foo.txt SUCCESS VolumeCreationTime: 31/01/2013 21:13:11, VolumeSerialNumber: 5003-210E, SupportsObjects: True, VolumeLabel: CSC ESOE 16:02:51,0970883 sh.exe 3192 QueryAttributeInformationVolume C:\pbtest\foo.txt SUCCESS FileSystemAttributes: Case Preserved, Case Sensitive, Unicode, ACLs, Compression, Named Streams, Object IDs, Reparse Points, Sparse Files, Quotas, Transactions, 0x3c00000, MaximumComponentNameLength: 255, FileSystemName: NTFS 16:02:51,0971132 sh.exe 3192 QueryNetworkOpenInformationFile C:\pbtest\foo.txt SUCCESS CreationTime: 18/09/2014 13:38:07, LastAccessTime: 18/09/2014 15:43:47, LastWriteTime: 18/09/2014 16:02:25, ChangeTime: 18/09/2014 16:02:25, AllocationSize: 01/01/1601 02:00:00, EndOfFile: 01/01/1601 02:00:00, FileAttributes: A 16:02:51,0971351 sh.exe 3192 CloseFile C:\pbtest\foo.txt SUCCESS 16:02:51,1362820 sh.exe 3192 CloseFile C:\pbtest\foo.txt SUCCESS
16:02:25,7924624 java.exe 5612 CreateFile C:\pbtest\foo.txt SUCCESS Desired Access: Generic Write, Read Attributes, Disposition: OverwriteIf, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Overwritten 16:02:25,9070108 sh.exe 6712 DeviceIoControl C:\pbtest\foo.txt INVALID PARAMETER Control: 0x1b0050 (Device:0x1b Function:20 Method: 0) 16:02:25,9070460 sh.exe 6712 QueryNameInformationFile C:\pbtest\foo.txt SUCCESS Name: \pbtest\foo.txt 16:02:25,9094194 sh.exe 6712 CreateFile C:\pbtest\foo.txt SUCCESS Desired Access: Read EA, Read Attributes, Read Control, Disposition: Open, Options: Open For Backup, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 16:02:25,9095628 sh.exe 6712 QueryInformationVolume C:\pbtest\foo.txt SUCCESS VolumeCreationTime: 31/01/2013 21:13:11, VolumeSerialNumber: 5003-210E, SupportsObjects: True, VolumeLabel: CSC ESOE 16:02:25,9095844 sh.exe 6712 QueryAttributeInformationVolume C:\pbtest\foo.txt SUCCESS FileSystemAttributes: Case Preserved, Case Sensitive, Unicode, ACLs, Compression, Named Streams, Object IDs, Reparse Points, Sparse Files, Quotas, Transactions, 0x3c00000, MaximumComponentNameLength: 255, FileSystemName: NTFS 16:02:25,9096107 sh.exe 6712 QueryNetworkOpenInformationFile C:\pbtest\foo.txt SUCCESS CreationTime: 18/09/2014 13:38:07, LastAccessTime: 18/09/2014 15:43:47, LastWriteTime: 18/09/2014 16:02:25, ChangeTime: 18/09/2014 16:02:25, AllocationSize: 01/01/1601 02:00:00, EndOfFile: 01/01/1601 02:00:00, FileAttributes: A 16:02:25,9096323 sh.exe 6712 CloseFile C:\pbtest\foo.txt SUCCESS 16:02:25,9332531 sh.exe 6712 WriteFile C:\pbtest\foo.txt SUCCESS Offset: 0, Length: 15, Priority: Normal 16:02:25,9335022 sh.exe 6712 CloseFile C:\pbtest\foo.txt SUCCESS
-- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple