Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 640
phi Avatar asked Dec 13 '08 00:12

phi


People also ask

How do I redirect console output to a file?

To redirect the output of a command to a file, type the command, specify the > or the >> operator, and then provide the path to a file you want to the output redirected to. For example, the ls command lists the files and folders in the current directory.

How do you save a terminal output on a Mac?

If you want to save the output of all the commands and their results for the current session in a text file on the macOS, you can do that by simply pressing Command + S keys, this will open a prompt that will ask you where you want to save the file to.

How do I write a file in Mac terminal?

In the Terminal app on your Mac, invoke a command-line editor by typing the name of the editor, followed by a space and then the name of the file you want to open. If you want to create a new file, type the editor name, followed by a space and the pathname of the file.


2 Answers

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.

like image 71
Lily Ballard Avatar answered Sep 19 '22 00:09

Lily Ballard


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.

like image 23
Chris Hanson Avatar answered Sep 19 '22 00:09

Chris Hanson