开发者

Setting up Eclipse to call my program with the following argument " < fileName.txt"

开发者 https://www.devze.com 2023-01-28 06:34 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消