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]

Re: stderr for Windows native commands are seemed to be bufferd


On 2/28/2013 10:39 PM, smith@cygwin.akamoz.jp wrote:
The stderr for Microsoft Windows native commands is undesirably
buffered when they are executed on Cygwin shell, Like this:

$ uname -a
CYGWIN_NT-6.1 localhost 1.7.17(0.262/5/3) 2012-10-19 14:39 i686 Cygwin
$ which nslookup
/cygdrive/c/Windows/system32/nslookup
$ nslookup
...
set q=hogehoge
set q=fugafuga
exit
unknown query type: hogehoge
unknown query type: fugafuga
$

The error messages "unknown query type" should comes just after
"set q=" input respectively.

Create a simple program as follows:

#include <stdio.h>
int main(void) {
	fprintf(stderr, "hogehoge\n");
	/* fflush(stderr); */
	getchar();
	fprintf(stderr, "fugafuga\n");
	return 0;
}

Build the program by MSVC:

c:\>cl /?
Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

On Microsoft's cmd, everything goes fine. On bash in Cygwin,
first waiting for input, then 2 lines are printed.
If I insert fflush just before getchar, it works well both environments.

Who is buffering the stderr output? Is there any workaround?

Windows is buffering because it sees the Cygwin ptys as a pipe (and it buffers on pipes for performance reasons). The alternative is to start bash from cmd.exe instead of mintty or other Cygwin terminal. See the email archives for more discussion of this issue if you're interested.

--
Larry

_____________________________________________________________________

A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?

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