Spewing stderr to an NSTextView

  • This is probably obvious/simple, but it has me baffled.  I have an
    NSTextView where I want to spew all the stderr output (e.g. NSLog output,
    etc. -- imagine the XCode2 run/log window).  This would be read-only
    (obviously), the only option I'm likely to allow is some combination of
    selection and "save to file...".  But that's not the question I am working
    on.

    I have the NSTextView, and I know how to open /dev/stderr as a file, but
    where I'm baffled is how to get the latter into the former. :)  Do I want to
    create a thread that just sits in a loop and waiting on a read from the file
    and then dumping that to the NSTextView?  Is there a more "cocoa" way to
    handle this such as some delegate/method down in NSTextStorage or something
    that I'm overlooking?  Suggestions/advice?

    I thought about writing my own version of NSLog that simply spews into the
    NSTextView, and I could write my NSLogs to that method, but that doesn't
    solve the problem.  On rare instances, the app gets an exception and gives
    meaningful output to stderr.  I'd like to catch that too.  If someone has
    another way to catch this output and toss it in there as well, as opposed to
    opening stderr as a file, that would work too.  In short, I'm looking for an
    exception log -> NSTextView method, and I'm open to all options.

    Thanks in advance for any assistance.
  • On 13.11.2007, at 00:39, Chris Williams wrote:

    > I have the NSTextView, and I know how to open /dev/stderr as a file,
    > but
    > where I'm baffled is how to get the latter into the former. :)

    Follow the Moriarity sample code (http://developer.apple.com/samplecode/Moriarity/
    ) and attach the NSFileHandle not to the forked but your apps stdout /
    stderr filehandles.
    Besides that, you might want to reconsider using you own log function
    that includes timestamps, log levels and filters depending on the
    loglevel  and / or read up on syslog and asl (man syslog, man asl)
  • Thanks, just what I was looking for.

    From: Thomas Engelmeier <te-work-list...>
    Subject: Re: Spewing stderr to an NSTextView

    Follow the Moriarity sample code
    (http://developer.apple.com/samplecode/Moriarity/
    ) and attach the NSFileHandle not to the forked but your apps stdout /
    stderr filehandles.
    Besides that, you might want to reconsider using you own log function
    that includes timestamps, log levels and filters depending on the
    loglevel  and / or read up on syslog and asl (man syslog, man asl)
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today