0

I am developing a application that reads from the stdin and does some computations on the data. I have currently set on Eclipse's Program's Arguments the following string:

< "input.txt"

where input.txt is the file I want to read from, but it doesn't seem to be working, as with the following code only "abc" is being printed:

char c;
printf("abc\n");
while ((c = getchar()) != EOF) {
    printf("%c", c);
}

What am I doing wrong?

devoured elysium
  • 101,373
  • 131
  • 340
  • 557
  • possible duplicate of [Eclipse reading stdin (System.in) from a file.](http://stackoverflow.com/questions/188547/eclipse-reading-stdin-system-in-from-a-file) – Bert F Dec 05 '10 at 20:06

1 Answers1

2

The < symbol is not a program argument, its a shell operator - it only works in a shell that understands it as part of parsing a command line.

Apparently, Eclipse doesn't use a shell to start up a Java programs and it doesn't itself process shell operators like < for starting up. I'll bet if you printed the command arguments in your program, you'd see < and input.txt. A shell would have processed them and not passed them to the program.

Unfortunately, I don't see anything in my version of Eclipse that suggests how to redirect the standard input to come from a file.

Bert F
  • 85,407
  • 12
  • 106
  • 123