views:

1613

answers:

4

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 side I am using Debug.Write(). I can see my debug output in xcode's console, but not in Terminal. I am tried:

$: open /path/build/Debug/MyProgram.app
$: open /path/build/Debug/MyProgram.app > output
$: open /path/build/Debug/MyProgram.app 2> output

on the shell and I am not seeing my output on the console or in 'ouput'.

Please help. Thanks.

PS. My ultimate goal is to write a vim plugin to manage, build, run, debug the xcode project. You can save me this hassle if you can get this vi input manager to work with xcode.

+2  A: 

Open Console.app in /Applications/Utilities All NSLog output will be printed in the System log. Or if you run it from within Xcode, all of the output will be printed in the Debug console. I'm not on my Mac right now and don't recall the command sequence or the menu the Debug Console is in. Possibly the Build menu?

Grant Limberg
I am trying to avoid using Xcode. I know what you're talking about. Cmd+Shift+R shows Xcode's console, and I see all my debug output there.
phi
I just looked at Console.app. It looks promising. I see all my output there; from NSLog() and Debug.Write().
phi
You're writing a Mac application, Xcode is how you do that.
Chris Hanson
+4  A: 

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.

Chris Hanson
+3  A: 

Chris gave a good overview of how the Console works, but to specifically answer your question, if you want to see the results directly in your Terminal, you need to run the built product as a child of the Terminal, which means using something like /path/debug/build/MyProgram.app/Contents/MacOS/MyProgram to launch the app.

Kevin Ballard
This works! Thank you.
phi
A: 

I use also that with gdb in order to debug Mac app directly from Terminal. $ gdb /path/debug/build/MyProgram.app/Contents/MacOS/MyProgram

But I wonder if it possible to attach a terminal directly from the application. In other words if the application can use its own console as it does with XCode Debug Console but without XCode.

Does anyone knows ? Thanks.