Eclipse reading stdin (System.in) from a file

2019-01-04 09:29发布

Is it possible for Eclipse to read stdin from a file?

11条回答
Animai°情兽
2楼-- · 2019-01-04 10:05

2015 update

There is a new Eclipse version, Eclipse 4.5 (Mars) which has fixed the issue!

This is the announcement and description of the feature: http://eclipse.org/mars/noteworthy/#_assigning_stdin_to_a_file

Stdin can now be assigned to a file in the Common tab of launch configuration dialogs. enter image description here

As expected, this is a new feature of the just released eclipse 4.5 and will therefore not work in an older version.

查看更多
闹够了就滚
3楼-- · 2019-01-04 10:05

This is surprisingly not supported in Eclipse and it seems there are no current plans to add it. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=155411 to follow and vote.

I will update here if it they do implement it.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-04 10:08

On the "common" tab of the run dialog, under "Standard Input and Output" there's a checkbox for "file". but it appears to be only for output...

I'd expect to see 2 file fields there, one for standard in, one for standard out with the append options.

查看更多
Lonely孤独者°
5楼-- · 2019-01-04 10:15

The solution for me (running on a Mac, using Eclipse CDT for a C application) was to add "< path/to/somefile" at the end of other arguments in the "Arguments" tab of the "Run Configuration" dialog.

Also check this other question for an answer involving launching a Java program in a suspended state and then attaching the debugger using Eclipse.

查看更多
Anthone
6楼-- · 2019-01-04 10:15

I don't see a nice way to do it using the standard Eclipse Run dialog. However, you might be able to do it with an External tool launcher and either use the standard "< infile" syntax or call a .bat/.sh script to do it for you.

It's not automated, which is what I'm guessing you want, but you can copy & paste the contents of your infile to the Eclipse console when you launch your program.

查看更多
登录 后发表回答