How to get the output of an OS X application on the console, or to a file?

前端 未结 4 1553
离开以前
离开以前 2020-12-04 14:44

I am writing a Cocoa application with Mono embedded. I want to run and see my debug output in Terminal. On the Cocoa side I am using NSLog(), and on the Mono s

4条回答
  •  情歌与酒
    2020-12-04 15:02

    Terminal on Mac OS X is just another application. Opening a terminal window for text I/O is not an inherent capability of every application as it is on Windows.

    Furthermore, open /path/to/MyApp.app does not execute MyApp.app as a subprocess of your shell, it sends a message to the operating system's launch infrastructure asking it to execute the application in a normal fashion, the same as if it were double-clicked in the Finder or clicked in the Dock. That's why you're not able to just redirect its output to see what your app is sending to stdout or stderr.

    You can use Console.app to see the output of applications launched in the normal manner, because the launch infrastructure specifically sends their stdout and stderr there. You can also use the asl routines to query the log, or perform more sophisticated logging if you so desire.

提交回复
热议问题