• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: write to the console
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: write to the console


  • Subject: Re: write to the console
  • From: Chris Kane <email@hidden>
  • Date: Wed, 23 Apr 2003 11:47:38 -0700

NSLog() and fprintf(stderr, ...) are both sending output to the same place, the stderr file of your process. When you run in a shell in a Terminal window, this output goes to the shell which spews it on to Terminal. (Well, that's somewhat simplified...) When you run, say, an app by double-click, it's stderr is redirected by "Finder" (it's perhaps simplest to think of Finder running the program, though that's not correct) as it is started, to point to /var/tmp/console.log (and again, this is not actually what is going on, but it's a much easier-to-understand explanation).

Look at freopen() in the stdio subsystem (see the man page), as a reasonable way to point your stderr at /var/tmp/console.log. Of course, it is always possible that the OS may change the name of that file in the future or put it somewhere else. Using freopen you can point stderr at whatever file you like, it wouldn't have to be the console log. Remember to use an append-without-truncation option, or you'll be blowing away the file when you run your tool.

You may only want to redirect your stderr when it is going to a Terminal or remote-logged-in-shell or similar. The simplest way to detect this is to use the often-overlooked function isatty() (again, see the man page) with STDERR_FILENO as the argument (<unistd.h>).


Chris Kane
Cocoa Frameworks, Apple


On Tuesday, April 22, 2003, at 23:40, Lloyd Dupont wrote:

well, I'm testing with a simple tool.
when I invoke it from the terminal NSLog() write in my terminal, but there is no output in the system console.
I tried fprintf(stderr, ...); too, but it doesn't work either ...


On Wednesday, April 23, 2003, at 04:34 PM, email@hidden wrote:

NSLog() is what I use

On Wed, 23 Apr 2003 16:19:34 +1000, Lloyd Dupont wrote:


how to write to the console ?
_______________________________________________
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.

__________________________________________________________
Get your FREE personalized e-mail at http://www.canada.com
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: write to the console
      • From: ryan <email@hidden>
References: 
 >Re: write to the console (From: Lloyd Dupont <email@hidden>)

  • Prev by Date: Re: netstat launched from within Cocoa?
  • Next by Date: NSData array?
  • Previous by thread: Re: write to the console
  • Next by thread: Re: write to the console
  • Index(es):
    • Date
    • Thread