有没有办法在Netbeans中将输入从文件重定向到stdin? [英] Is there a way to redirect input from file to stdin in Netbeans?

查看:120
本文介绍了有没有办法在Netbeans中将输入从文件重定向到stdin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans和Maven开发应用程序。我的应用程序应该从stdin获取数据。但我无法理解如何测试它。放< data.txt 进入args列表不起作用。

I'm developing application with Netbeans and Maven. My application should obtain data from stdin. But I could not understand how to test it. Putting < data.txt into args list does not work.

我需要相同的:

$ java MyProgram < data.txt 


推荐答案

这可以通过添加自己的将target运行到项目的build.xml文件中。例如:

This can be done by adding your own run target to your project's build.xml file. For example:

<target name="run" depends="jar">
  <exec dir="${work.dir}" executable="java" input="${work.dir}/inputfile.txt">
    <arg value="-jar"/>
    <arg file="${dist.jar}"/>
  </exec>
</target>

请注意,如果编译,Run,Debug和Test等命令仅使用自定义build.xml关闭项目的保存功能。因此,您需要确保在项目的属性中关闭保存时编译。

Note that commands such as Run, Debug, and Test only use your custom build.xml if the Compile on Save feature is turned off for the project. So you will need to ensure that Compile on Save is turned off in your project's properties.

这篇关于有没有办法在Netbeans中将输入从文件重定向到stdin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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