xcode 如何在控制台或文件中获取 OS X 应用程序的输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/364564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the output of an OS X application on the console, or to a file?
提问by phi
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:
我正在编写一个嵌入 Mono 的 Cocoa 应用程序。我想在终端中运行并查看我的调试输出。我在 Cocoa 端使用NSLog()
,在 Mono 端我使用Debug.Write()
. 我可以在 Xcode 的控制台中看到我的调试输出,但在终端中看不到。这是我尝试过的:
$: 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 managerto work with xcode.
附注。我的最终目标是编写一个 vim 插件来管理、构建、运行、调试 xcode 项目。如果你能让这个vi 输入管理器与 xcode 一起工作,你就可以省去我的麻烦。
回答by Lily Ballard
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
Chris 很好地概述了控制台的工作原理,但要专门回答您的问题:如果您想直接在终端中查看结果,则需要将构建的产品作为终端的子项运行,这意味着使用类似
/path/debug/build/MyProgram.app/Contents/MacOS/MyProgram
to launch the app.
启动应用程序。
回答by Chris Hanson
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.
Mac OS X 上的终端只是另一个应用程序。为文本 I/O 打开终端窗口并不是每个应用程序的固有功能,因为它在 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 itto 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
.
此外,open /path/to/MyApp.app
不会将 MyApp.app 作为 shell 的子进程执行,它会向操作系统的启动基础结构发送一条消息,要求它以正常方式执行应用程序,就像在 Finder 中双击或单击它一样在码头。这就是为什么您不能仅重定向其输出以查看您的应用发送到stdout
或 的原因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.
您可以使用 Console.app 查看以正常方式启动的应用程序的输出,因为启动基础结构专门发送它们stdout
并stderr
在那里发送。您还可以使用asl
例程来查询日志,或者根据需要执行更复杂的日志记录。
回答by Grant Limberg
Open Console.app in /Applications/Utilities. All NSLog output will be printed in the System log.
在 /Applications/Utilities 中打开 Console.app。所有 NSLog 输出都将打印在系统日志中。
Or, if you run it from within Xcode, all of the output will be printed in the Debug console.
或者,如果您在 Xcode 中运行它,所有输出都将打印在调试控制台中。
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?
我现在不在 Mac 上,不记得调试控制台所在的命令序列或菜单,可能是构建菜单?
回答by abbood
Overview
概述
The idea is to simply run the app from command line using ios-deploy.
这个想法是简单地使用ios-deploy从命令行运行应用程序。
Instructions
指示
- Install ios-deploy
- Run the app from xcode (make sure it runs successfully)
- go to xcode menu > preferences > locations and click on arrow in derived data:
- in the derived data directory, search for your .app file under Build/intermediates/Products
- 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 thisios-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.
- 安装ios-deploy
- 从 xcode 运行应用程序(确保它运行成功)
- 转到 xcode 菜单 > 首选项 > 位置,然后单击派生数据中的箭头:
- 在派生数据目录中,在 Build/intermediates/Products 下搜索您的 .app 文件
- 在终端中键入以下内容,
ios-deploy --debug --bundle
然后将 .app 文件从第 4 步拖到终端中.. 你应该有这样的东西ios-deploy --debug --bundle path/to/your/applicationName.app
,就是这样!该应用程序应该会成功运行,并且所有日志都将转到您的终端。