views:

1101

answers:

3

Hi, Is it possible to use IO 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. Anybody know how to do this?

Cheers

+1  A: 

Does this help?

Andrew Coleson
+2  A: 

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...

Jon Skeet
Thats what I was just about to reply to say... Yeah, It looks like its not possible to do it cleanly in eclipse, so i'll just keep a terminal open I suppose. Thanks
Simonw
+2  A: 
VonC
cool, I'll try that now
Simonw
Oh still here ? :) Please try it first before removing the "accepted" answer from Jon. Remember: "Users don't mark Jon Skeet's answers as accepted. The universe accepts them out of a sense of truth and justice." ( http://stackoverflow.com/questions/305223/jon-skeet-facts/310323#310323 )
VonC