Eclipse 中的 I/O 重定向?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/799250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I/O redirection in Eclipse?
提问by Simonw
Is it possible to use I/O redirection in Eclipse?
是否可以在 Eclipse 中使用 I/O 重定向?
I want to redirect standard input/output on the command line like java MyProgram <input.txt >output.txt
, but I can't seem to get it to work in Eclipse. I tried including the <'s as part of the program arguments, which was ignored, and also in the VM arguments, which just threw up a class not found error. How can I do this?
我想在命令行上重定向标准输入/输出,如java MyProgram <input.txt >output.txt
,但我似乎无法让它在 Eclipse 中工作。我尝试将 < 作为程序参数的一部分,这被忽略了,还有在 VM 参数中,它只是抛出了一个未找到类的错误。我怎样才能做到这一点?
采纳答案by VonC
To truly redirect both, the simplest way is still to define your program as an external script
要真正重定向两者,最简单的方法仍然是将您的程序定义为外部脚本
"java %1 %2 %3 %4 < %5 > %6"
(adapt the number of parameters to your particular program)
(根据您的特定程序调整参数数量)
In the Run menu, click 'External Tools.../Open External Tools Dialog" and define an external launch configuration in which you will specify both the arguments and the input and output file.
在“运行”菜单中,单击“外部工具.../打开外部工具对话框”并定义一个外部启动配置,您将在其中指定参数以及输入和输出文件。
It is not an ideal solution though, as you cannot debug directlyyour code (with a "debug" launcher configuration).
Instead you have to remote debug it (add '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
' in your generic Java launcher script)
但是,这不是理想的解决方案,因为您无法直接调试代码(使用“调试”启动器配置)。
相反,您必须远程调试它(-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
在您的通用 Java 启动程序脚本中添加 ' ')
Once you have launched your external tool, launch a remote debug session through the "debug launcher 'Remote Java Application'" section:
启动外部工具后,通过“调试启动器‘远程 Java 应用程序’”部分启动远程调试会话:
回答by Jon Skeet
You can redirect outputusing the Run dialog, Common tab, "Standard Input and Output" section.
您可以使用“运行”对话框、“通用”选项卡、“标准输入和输出”部分来重定向输出。
However, it doesn't look like you can redirect inputas far as I can tell (and as far as this Stack Overflow questioncan tell, too).
但是,据我所知,您似乎无法重定向输入(并且就这个 Stack Overflow 问题而言)。
How much control do you have over your application? If you don't mind a bit of a hack, you could have a couple of properties or command line arguments to determine the appropriate files, and use System.setOut
and System.setIn
accordingly. It isa bit of a hack though...
您对您的应用程序有多少控制权?如果你不介意一个黑客位的,你可以有几个属性或命令行参数来确定相应的文件,并使用System.setOut
与System.setIn
相应。这是一个黑客位的,虽然...