Setting up Eclipse to call my program with the following argument " < fileName.txt"
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开发者_如何学Go 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?
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.
精彩评论