Re: NSTask output only after termination of NSTask
Re: NSTask output only after termination of NSTask
- Subject: Re: NSTask output only after termination of NSTask
- From: Alastair Houghton <email@hidden>
- Date: Tue, 19 Feb 2008 12:03:49 +0000
On 18 Feb 2008, at 22:11, [nexUmoja] Fabian Jäger wrote:
I have the following problem: I try to use the common mechanism to
read the output of an NSTask by using NSFileHandle and
NSFileHandleReadCompletionNotification...
Unfortunately the output is displayed as a huge chung only after the
termination of the NSTask. If I start the executable in the terminal
the ouput comes continously and not after the termination! What
could be the problem? Maybe the output comes too fast and fills the
buffer?
The problem is that the program you are communicating with is using
buffered I/O, and its output buffer is not filling up, so it never
actually writes to the pipe. The data is just sitting in buffers in
the C library.
If you're writing a program of your own that has this problem, you can
use the setvbuf() function to set the C library's I/O buffering to a
more appropriate mode, or you can add fflush() calls in appropriate
places. The setvbuf(3) man page describes the default behaviour,
which is line buffered for terminal devices, unbuffered for stderr,
and block buffered elsewhere.
If you're trying to control a third-party program (which it seems you
are in this case), then depending on exactly how you're using it and
how it was written, you may need to use a pty to control the program.
Sometimes you can get by without doing that, especially with programs
that were designed to be used in a pipe, but even then you may find
that you have to close the input side of the pipe before you get all
the output.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden