public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* stderr for Windows native commands are seemed to be bufferd
@ 2013-03-01  3:39 smith
  2013-03-01  4:21 ` Larry Hall (Cygwin)
  0 siblings, 1 reply; 2+ messages in thread
From: smith @ 2013-03-01  3:39 UTC (permalink / raw)
  To: cygwin

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?

Best Regards.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: stderr for Windows native commands are seemed to be bufferd
  2013-03-01  3:39 stderr for Windows native commands are seemed to be bufferd smith
@ 2013-03-01  4:21 ` Larry Hall (Cygwin)
  0 siblings, 0 replies; 2+ messages in thread
From: Larry Hall (Cygwin) @ 2013-03-01  4:21 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-01  4:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-01  3:39 stderr for Windows native commands are seemed to be bufferd smith
2013-03-01  4:21 ` Larry Hall (Cygwin)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).