Bad interaction between cygwin and ProcessBuilder when redirecting stdout

Pierre Bogossian bogossian@mail.com
Thu Sep 18 22:20:00 GMT 2014


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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pb_append.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140918/9b5c6984/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pb_write.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140918/9b5c6984/attachment-0001.txt>
-------------- next part --------------
--
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


More information about the Cygwin mailing list