问题描述
以前,eclipse中有一个阻止了运行从重定向文件到stdin的配置,但据说它是固定的。但是,现在已经修复,我找不到任何文档来说明如何操作。
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.
很容易会误解我要完成的工作,所以让我成为明确。我不是在寻找可以读取文件的代码。我不希望将文件名作为arg传递。我不希望重定向stdout或stderr。
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();
从文件重定向输入当然可以在命令提示符下完成,但我正在尝试获取eclipse配置为在按下ctrl-F11按键时即可自动执行此操作。
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.
推荐答案
Eclipse 4.5(Mars)功能的公告和描述:
This is the announcement and description of the feature for Eclipse 4.5 (Mars): http://eclipse.org/mars/noteworthy/#_assigning_stdin_to_a_file
如预期的那样,这是刚刚发布的Eclipse 4.5的新功能,因此在较旧版本中将不起作用。
As expected, this is a new feature of the just released Eclipse 4.5 and will therefore not work in an older version.
这篇关于使用运行配置从Eclipse中的文件重定向stdin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!