I'm having issues with getting xcode project output to display into my terminal.app. I can get the terminal to pop up on run, but how do I get the "output" to display into the terminal.app.
Asked
Active
Viewed 2,257 times
2 Answers
0
All NSLog are printed automatically in System log in Terminal.app.
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.
EDIT:
If you want to redirect the NSLog to a file use :
-(void) redirectNSLogToFile {
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath=[paths objectAtIndex:0];
NSString *logPath=[filePath stringByAppendingPathComponent:@"LogFile.txt"];
freopen([logpath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}

Community
- 1
- 1

Anoop Vaidya
- 46,283
- 15
- 111
- 140
-
So, I don't have to use the output files in xcdoe? – TWcode Mar 06 '13 at 17:26
-
What I really want is to get the apps output and export it into a text file. Is that possible or am I over thinking things? – TWcode Mar 06 '13 at 17:34
-
If you look at the pic you can see the output that I'm getting from my app in the "all output" screen. Is there a way to display that into a text file and/or terminal? – TWcode Mar 06 '13 at 17:36
-
I like this, but I made the file LogFile.txt and nothing happened. Where would I stick this method? – TWcode Mar 06 '13 at 18:30
-
whereever you write nslog, replace this with that – Anoop Vaidya Mar 06 '13 at 19:12
-
and always point to user by @username, the i will get the message :) – Anoop Vaidya Mar 06 '13 at 19:13
0
When you run your app in Xcode all the output is in the 'All Output' pane. If you want to preserve that just: select it, copy it, and paste it into a file (created with TextEdit or whatever).
By default, running your app in the Terminal.app won't preserve the output. You can use Unix pipes/redirects to get it into a file with, for example:
$ /path/to/myapp > /path/to/LogFile.txt

GoZoner
- 67,920
- 20
- 95
- 145
-
-
The above is what you would type in the Terminal.app, to the shell (which is what actually runs in the Terminal.app). – GoZoner Mar 06 '13 at 18:49
-
Getting this error message /path/to/LogFile.txt: No such file or directory – TWcode Mar 06 '13 at 18:54
-
The notation '/path/to' means that you need to provide that information. The error message is saying that '/path/to' doesn't exist; which is true. If you want 'LogFile.txt' to be in your 'Home' folder use "~/LogFile.txt"; if you want it on your Desktop use "~/Desktop/LogFile.txt" – GoZoner Mar 06 '13 at 19:04