Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect stdin from a file in eclipse with run configuration

Tags:

java

eclipse

There used to be a bug in eclipse that prevented a run configuration from redirecting a file to stdin but supposedly it's fixed. However, I can't find any documentation that tells how to do it now that it's fixed.

It's easy to misunderstand what I'm trying to accomplish so let me be clear. I'm not looking for code that will read a file. I'm not looking to pass a filename as an arg. I'm not looking to redirect stdout or stderr.

I have existing code that takes normal standard input without knowing if it's coming from the keyboard or a file:

scanner = new Scanner(System.in);
number = scanner.nextInt();

Redirecting input from a file can be done at a command prompt of course but I'm trying to get eclipse configured to do it automatically at the touch of a ctrl-F11 keystroke.

Fair warning, I've done a number of web searches trying to answer this myself and many of them claim the answer is in Run Configuration | Common but they end up only working for stdout.

like image 505
candied_orange Avatar asked Jul 05 '15 20:07

candied_orange


1 Answers

This is the announcement and description of the feature for Eclipse 4.5 (Mars): 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.

like image 196
Petr Janeček Avatar answered Nov 15 '22 19:11

Petr Janeček