Reputation: 1514
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.
How can I do this with Xcode?
Upvotes: 2
Views: 2382
Reputation:
You can't, unfortunately. I'm having to modify my program to read from a file for debugging purposes, like this:
NSFileHandle *input;
if (AmIBeingDebugged())
input = [NSFileHandle fileHandleForReadingAtPath:@"/Users/me/debug.input"];
else
input = [NSFileHandle fileHandleWithStandardInput];
The source for AmIBeingDebugged is here.
Upvotes: 1
Reputation: 16515
Just for better clarification of @Nestor's answer....
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);
}
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 sends the files contents into stdin.
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.
to set up the xcode argument, go to:
Product > Scheme > edit scheme
Then set up the argument 'debug' in the run scheme:
Upvotes: 4
Reputation: 4529
You can pipe data into the executable of an Xcode project for debugging.
See my answer to a similar Stackoverflow question here.
(copied for convenience):
In Xcode 4.5.1:
dmzfrqdevydjuqbexdivolfeujsj/Build/Products/Debug/
)Launch your app piping in whatever you want into standard input:
echo mydata | ./MyApp.app/Contents/MacOs/MyApp
Switch back to Xcode and the debugger will have detected your application's launch and attached to it.
Upvotes: 4