This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bad interaction between cygwin and ProcessBuilder when redirecting stdout


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

Attachment: pb_append.txt
Description: Text document

Attachment: pb_write.txt
Description: Text document

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]