You can't get there from here. The problem is that when the shell sees "> foo", it truncates foo immediately, before running the command line. Your program will see an empty file, and I'm guessing that the error comes from that. Posting what the error is would help though.
example:
Code:
13:24 aluser@alf:/tmp$ echo blah > foo
13:24 aluser@alf:/tmp$ cat < foo > foo
13:24 aluser@alf:/tmp$ cat foo
13:24 aluser@alf:/tmp$
The contents of foo disappear with the cat < foo > foo line.