Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I/O redirection in Eclipse?

Is it possible to use I/O redirection in Eclipse?

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?

like image 865
Simonw Avatar asked Apr 28 '09 18:04

Simonw


2 Answers

You can redirect output using the Run dialog, Common tab, "Standard Input and Output" section.

However, it doesn't look like you can redirect input as far as I can tell (and as far as this Stack Overflow question can tell, too).

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 is a bit of a hack though...

like image 141
Jon Skeet Avatar answered Oct 04 '22 11:10

Jon Skeet


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 directly your 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)

Once you have launched your external tool, launch a remote debug session through the "debug launcher 'Remote Java Application'" section:

Remote Debug, after blog.jmwyttenbach.net/wp-content/uploads/2007/10/eclipseremotedebug.jpg

like image 39
VonC Avatar answered Oct 04 '22 10:10

VonC