使用运行配置从Eclipse中的文件重定向stdin [英] Redirect stdin from a file in eclipse with run configuration

查看:113
本文介绍了使用运行配置从Eclipse中的文件重定向stdin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,eclipse中有一个 bug 阻止了运行从重定向文件到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)功能的公告和描述: http://eclipse.org/mars/ noteworthy /#_ assigning_stdin_to_a_file

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现在可以在 Common 标签的启动
配置对话框。

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

如预期的那样,这是刚刚发布的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆