在Xcode下运行应用程序 [英] Piping Into Application Run Under Xcode

查看:197
本文介绍了在Xcode下运行应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OS X Lion上的Xcode来调试C命令行应用程序。应用程序通过标准输入需要大量输入数据。在shell上,我只是将一个文本文件导入到这个应用程序中。

I'm trying to debug a C command line application using Xcode on OS X Lion. The application needs a lot input data via standard input. On the shell I just pipe a text file into this application.

我如何用Xcode来实现?

How can I do this with Xcode?

推荐答案

只是为了更好地澄清@ Nestor的回答....

Just for better clarification of @Nestor's answer....

我无法想出一个管道进入x -code,所以我在脚本的开头添加了以下代码,该代码从测试文件称为测试文件。

I couldn't figure out a way to pipe into x-code so I added the following code at the beginning of my script that piped from a test file called test file.

    // For debugging
if (argc == 2 && strcmp(argv[1], "debug") == 0 ) {
    printf("== [RUNNING IN DEBUG MODE]==\n\n");
    char test_file_path[] = "/Users/bonobos/are/amazing/test.txt";
    freopen(test_file_path, "r", stdin);
}

请注意,我需要完整的文件路径,因为当xcode编译时,奇怪的随机文件夹,所以如果你不想打扰包装你最好使用绝对路径的文本资源。

Note that I need the full file path because when xcode compiles it goes to some weird random folder and so if you don't want to bother packaging the text resources you're better off using an absolute path.

freopen将文件内容发送到stdin。

freopen sends the files contents into stdin.

也是因为我有这个if语句我设置了xcode有参数的调试。这个做法是用评论来做的,当你为realsies编译时忘记取消注释。

also because I have that if statement I set up xcode to have the argument of debug. this beats doing it with comments and forgetting to uncomment when you compile for realsies.

设置xcode参数,转到:

to set up the xcode argument, go to:

产品>计划>编辑方案

Product > Scheme > edit scheme

然后设置参数'debug'运行方案:

Then set up the argument 'debug' in the run scheme:

这篇关于在Xcode下运行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆