Re: Redirect stderr to NSTextView
Re: Redirect stderr to NSTextView
- Subject: Re: Redirect stderr to NSTextView
- From: Sherm Pendley <email@hidden>
- Date: Sun, 20 Jun 2004 16:10:33 -0400
On Jun 20, 2004, at 7:05 AM, Gerriet M. Denkmann wrote:
I have an app, which uses a function, which has rather many calls to
fprintf(stderr,...).
I would like to have this output not go to console.log but directly
into a NSTextView of my app.
Is there a simple way to do this?
(It must be possible, because Xcode does it.)
If I understand you correctly, Xcode is doing something rather
different. It's not redirecting its own stderr, it's capturing a child
process' stderr. That's easy to do by using NSTask methods to launch
the child process and direct its input/output streams.
Or should one redirect (from inside my app) stderr to some /tmp/mess
(probably using freopen() ) ?
Then I could, after the function has returned, put this file into my
NSTextView.
I would log the output to a regular .log file in ~/Library/Logs, rather
than to a temp file - it could be useful to review it later. But that's
a minor point.
To implement the "view log" window, I'd have it start another thread
(to avoid blocking) and in the subthread run "tail -f" with NSTask.
Whenever input is received from the "tail -f", tell the main thread to
append it to the text view. This will save you the trouble of
monitoring the log file, remembering its size when it was last written
to, etc. - all that logic is already present in "tail".
When you close the window, you'll need to terminate the "tail" task
with NSTask's -terminate method, because "tail -f" loops forever and
never exits on its own.
sherm--
_______________________________________________
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.