NSTask and avoiding buffered standard out
NSTask and avoiding buffered standard out
- Subject: NSTask and avoiding buffered standard out
- From: Jim Correia <email@hidden>
- Date: Mon, 12 Aug 2002 17:31:50 -0400
I've got a test tool which writes alternate lines to stdout that look
like
some output
STDERR: some output
some output
STDERR: some output
etc.
When I do the NSTask dance (using the same pipe for stderr and stdout),
and display the output as I would get it, I get
STDERR: some output
STDERR: some output
some output
some output
It isn't terribly surprising, since the man pages say that stdout is
normally block buffered when it isn't attached to a tty, and stderr is
usually unbuffered.
I tried getting rid of the buffer on stdout, but that didn't seem to do
the trick.
#include <stdio.h>
int main (int argc, const char * argv[])
{
FILE *stream = popen("/Users/correia/Desktop/std-
test/build/std-test", "r");
char buffer[1024];
if (0 != setvbuf(stream, NULL, _IONBF, 0))
printf("setvbuf failed\n\n\n");
while (NULL != fgets(buffer, 1024, stream))
{
printf("%s", buffer);
}
pclose(stream);
return 0;
}
(I know that snippet doesn't use NSTask - I went down to almost basic
(used popen rather than wrangling the pipes myself for brevity)).
Is there a way to avoid this buffering without writing a pseudo tty
(which is ugly and not something I want to do if I can avoid it.)
Thanks,
Jim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.