# XCode help - specifying the source of stdin



## g4c9z (May 1, 2008)

I am trying to write a command-line application with XCode.

My application takes input from stdin.  The way I normally use it is to use redirection to specify the input file.  For example:


```
program < input.txt
```

In XCode, this is presumably specified by creating an executable and editing its info, via Project -> Edit Active Executable "...".

But the dialog doesn't explain how to specify where input comes from.  Changing the arguments to include "< input.txt" doesn't work, I guess because "<" is a symbol known to the Terminal, and XCode probably bypasses the Terminal.  Changing the option to "Use Pipe for standard input/output" seems to have no effect - perhaps there's a way to specify a pipe, but the dialog won't let me.  Searching the XCode User's Guide didn't explain it either - it mentions the "Use Pipe"  option, but doesn't describe how it works.

How can I get standard input from a file?


----------



## Viro (May 3, 2008)

Use the C function freopen. You should never bank on the terminal being present and C already has a standard function to do I/O redirection. See http://www.cplusplus.com/reference/clibrary/cstdio/freopen.html for an example of how to use this function.


----------



## g4c9z (May 3, 2008)

Thanks.  Yeah, modifying my program is always an option, and is the workaround I've settled on.  It would still be nice to know how the Xcode "pipe" option works though.


----------



## Viro (May 12, 2008)

Hmm... don't really know the answer to this. Did you manage to find out?


----------



## g4c9z (May 12, 2008)

No.  I just modified my program to take the file as an argument instead of forcing it to be through standard input.  It's not a big deal for me,  but I imagine there are other people who can't or don't want to do that, and would like to find an answer to my question.


----------



## hardnett (Jan 15, 2010)

I just tried this with Xcode 3.1 and it works to put the argument "< input.txt" as the first argument without the quotes of course. The argument entry is found by "Get Info" on the executable object in your Xcode project.


----------



## cfshelor (Apr 17, 2012)

I am having the same problem with Xcode 4.2.  I am trying to complete a homework exercise in a Compiler Design course and we are using Lex and YACC.  I completed assignments 1-3 with no issues but I am now getting a segmentation fault when running the code and want to run it under Xcode so I can see where the problem is occurring; however, I cannot figure out how to get my source code test file to be redirected as standard input.  The solution for Xcode 3.1 does not work for 4.2.  (no Get info, available)  Sure could use some help here ;-)

Thanks,

Charles


----------

