X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=0.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_WEB,SPF_HELO_PASS X-Spam-Check-By: sourceware.org From: "James Johnston" To: References: <004e01ccfd70$c69af3f0$53d0dbd0$@motionview3d.com> <005c01ccfd79$6341f980$29c5ec80$@motionview3d.com> <007201ccfe25$130065e0$390131a0$@motionview3d.com> <20120309195247 DOT GB18960 AT calimero DOT vinschen DOT de> <20120311013339 DOT GA32518 AT ednor DOT casa DOT cgf DOT cx> <00b701cd0059$25c26a80$71473f80$@motionview3d.com> <20120312141929 DOT GE2382 AT calimero DOT vinschen DOT de> <00cf01cd0075$8430b290$8c9217b0$@motionview3d.com> <20120312220204 DOT GA29921 AT ednor DOT casa DOT cgf DOT cx> In-Reply-To: <20120312220204.GA29921@ednor.casa.cgf.cx> Subject: RE: Can't reliably redirect standard output from C# program in recent Cygwin Date: Tue, 13 Mar 2012 14:58:09 -0000 Message-ID: <00ec01cd0129$b60043d0$2200cb70$@motionview3d.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Just tried the DLL from the snapshot and both my programs work fine now. :) I think I found what you refer to... From ReadFile page: ==== "If the lpNumberOfBytesRead parameter is zero when ReadFile returns TRUE on a pipe, the other end of the pipe called the WriteFile function with nNumberOfBytesToWrite set to zero." "When a synchronous read operation reaches the end of a file, ReadFile returns TRUE and sets *lpNumberOfBytesRead to zero." "If an anonymous pipe is being used and the write handle has been closed, when ReadFile attempts to read using the pipe's corresponding read handle, the function returns FALSE and GetLastError returns ERROR_BROKEN_PIPE." ==== So if I'm reading this right, if reading a file, I'd look for a successful return and number of bytes read == 0? But for a pipe, instead that situation should be *ignored* and instead I should look for an ERROR_BROKEN_PIPE to signify "end of file"? Really? That's tricky. I learned something new. I'm not sure if it's really the best design on Microsoft's part, because now you can't even easily write a generic "read file until end-of-file" function since it would have to be special-cased for pipes (and who knows what else). I wonder why it worked sometimes but not other times (e.g. running "echo `./HelloCPP | cat`" would sometimes work, sometimes not)? With something like this, I would think it would not work 100% of the time. Best regards, James Johnston -----Original Message----- Sent: Monday, March 12, 2012 22:02 Subject: Re: Can't reliably redirect standard output from C# program in recent Cygwin On Mon, Mar 12, 2012 at 05:28:17PM -0000, James Johnston wrote: >Well, good call. I shouldn't have jumped to conclusions. Both my C++ >and C# examples still fail: Not really a call. It was obviously different failure. The previous fix wasn't even pipe related. But, regardless, Corinna (who has more time these days to look into this type of thing) found a damning piece of MSDN documentation which indicates that a write of zero bytes to a pipe will cause a read of zero bytes on the other end of the pipe. So, a program which assumes that a zero byte read means EOF, like most Linux programs, will stop processing when it sees the zero bytes from ReadFile. Corinna sent me a patch to fix the problem which I've mildly tweaked and installed. It's in the latest snapshot. cgf -- 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 -- 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