55

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. This is what I tried:

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

in a terminal but I do not my output on the console or in 'ouput'.

What's the correct command?

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
phi
  • 1,513
  • 1
  • 15
  • 34

4 Answers4

77

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.

Ronny Brendel
  • 4,777
  • 5
  • 35
  • 55
Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • 1
    Worked for me too - thanks! For others who stumble across this answer, it basically means to run ./MyProgram.app/Contents/MacOS/MyProgram if you are in the directory that contains the .app. – dmonopoly Apr 02 '12 at 22:19
  • 1
    what do you mean by `/path/debug/build`? I want to see execution log for PhpStorm on my Mac OS X Sierra – Peyman Mohamadpour Oct 06 '17 at 11:55
  • `/path/debug/build` was meant to be a placeholder for the path to your built products folder. – Lily Ballard Oct 06 '17 at 17:53
  • 2
    Sadly this isn't exactly the same as `open MyProgram.app`. I've build some app which works fine when run directly, but when you open the app it just exits immediately. – Timmmm Oct 18 '19 at 18:21
  • Similar case to @Timmmm, I was able to debug by temporarily removing my `~/.profile` (which removed whatever envvariable or alias was letting my app work executed from the terminal but not when opening the app) – Alec Jacobson Feb 12 '20 at 12:26
  • 1
    This doesn't seem to work with every app, though (e.g. if they load custom libraries). – Eric Duminil Oct 16 '21 at 08:58
16

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
12

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?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Grant Limberg
  • 20,913
  • 11
  • 63
  • 84
  • 1
    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 Dec 13 '08 at 03:20
  • I just looked at Console.app. It looks promising. I see all my output there; from NSLog() and Debug.Write(). – phi Dec 13 '08 at 04:20
  • 3
    Doesn't mean you have to cripple your development by using their utterly naff and crashy IDE. :) – Ian Mar 13 '15 at 14:13
  • This answer is the most useful if you are trying to debug problems that occur when running the bundle app. Running in a terminal can change results and show different log messages. In my case, my bundle app failed to launch, but launching from the terminal succeeds. The Console.app log messages helped me to identify missing bundle entitlements that are given by default to terminal launched applications. – NaderNader May 01 '20 at 13:22
0

Overview

The idea is to simply run the app from command line using ios-deploy.

Instructions

  1. Install ios-deploy
  2. Run the app from xcode (make sure it runs successfully)
  3. go to xcode menu > preferences > locations and click on arrow in derived data: enter image description here
  4. in the derived data directory, search for your .app file under Build/intermediates/Products
  5. in the terminal type the following ios-deploy --debug --bundle then drag the .app file from step 4 unto the terminal.. you should have something like this ios-deploy --debug --bundle path/to/your/applicationName.app and that's it! The app should successfully run and all the logs will go to your terminal.
abbood
  • 23,101
  • 16
  • 132
  • 246