如何在终端上显示 Xcode 输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13598217/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:11:59  来源:igfitidea点击:

How to display Xcode output on Terminal?

cxcodemacosterminalclear

提问by Eugene

How do I run a C programming language from Xcode on terminal? Please help me with this by answering a step by step procedure in doing this. Thanks.

如何在终端上从 Xcode 运行 C 编程语言?请通过回答执行此操作的分步程序来帮助我解决此问题。谢谢。

Version 10.7.5 on a Macbook Air.

Macbook Air 上的 10.7.5 版。

采纳答案by bames53

Xcode isn't intended to run the program so that it displays its output in an external program like Terminal.app. It could probably be done by messing with the scheme configuration, but it's probably not a good idea.

Xcode 不打算运行该程序,以便它在诸如 Terminal.app 之类的外部程序中显示其输出。这可能可以通过弄乱方案配置来完成,但这可能不是一个好主意。

If you want a program's output to appear in Terminal.app then you should run the program in Terminal. To do this go to your project's build directory, find the executable and then copy the path into Terminal. Run the program.

如果您希望程序的输出出现在 Terminal.app 中,那么您应该在终端中运行该程序。为此,请转到项目的构建目录,找到可执行文件,然后将路径复制到终端中。运行程序。



Given your comment it's not clear what you're asking. It sounds like maybe you're asking if the commands passed to system()can also be used directly when running Terminal.app. The answer to that question is 'yes'.

鉴于您的评论,尚不清楚您在问什么。听起来您可能在问传递给的命令是否system()也可以在运行 Terminal.app 时直接使用。这个问题的答案是“是”。

You give an example system("cls"). If you're attempting to run the command clsin Terminal.app and finding that it doesn't work, the reason for that it's a Windows command. system("cls")works only on Windows, and the command clscan also be used directly in cmd.exe on Windows. system("cls")does not work on OS X, nor does a command clswork in Terminal.app.

你举个例子system("cls")。如果您尝试cls在 Terminal.app 中运行该命令并发现它不起作用,则原因是它是 Windows 命令。system("cls")仅适用于 Windows,该命令cls也可以直接在 Windows 上的 cmd.exe 中使用。system("cls")不适用于 OS X,也不cls适用于 Terminal.app中的命令。

The command that works in Terminal.app to clear the screen is clear, and if you want to use this command from inside a C program you can use system("clear").

在 Terminal.app 中用于清除屏幕的命令是clear,如果您想从 C 程序内部使用此命令,您可以使用system("clear").

回答by Parag Bafna

Write xcode output to file and run tail -fin terminal.

将 xcode 输出写入文件并tail -f在终端中运行。

int main(int argc, char *argv[])
{
    NSAutoreleasePool *nsp = [[NSAutoreleasePool alloc] init];
    NSString *logPath =[NSString stringWithFormat:@"%@/xcode.log",NSHomeDirectory()];
    freopen([logPath fileSystemRepresentation], "a", stderr);
    [nsp release];
    return NSApplicationMain(argc,  (const char **) argv);
}  
$ tail -f /homeDir/xcode.log

回答by Dhaval H. Nena

Simply type below keys while you're in in terminal, and it will clear the logs:

只需在终端中键入以下键,它就会清除日志:

Command + K

命令 + K