NSTask output only after termination of NSTask
-
Hey guys,
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?
Please help me :)
Fabian -
The program whose output you're trying to read may be designed to
behave differently according to whether or not its stdout is a tty.
Hamish
On Feb 18, 2008 10:11 PM, [ nexUmoja ] Fabian Jäger
<fabian.jaeger...> wrote:> Hey guys,
> 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?
> Please help me :)
>
> Fabian -
hmm, the tool I want to control is /usr/sbin/racoon ... Maybe someone
can test it? Is it possible that the output comes too fast for the
NSFileHandle?
Fabian
Am 18.02.2008 um 23:52 schrieb Hamish Allan:> The program whose output you're trying to read may be designed to
> behave differently according to whether or not its stdout is a tty.
>
> Hamish -
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


