Wednesday, March 25, 2020

Redirecting Stdout in Eclipse

There must be some way to redirect stdout from the console to a file in Eclipse.  No instructions that I can find look like Eclipse Oxygen.  I used to know how to execute java classes from the command line. (All my early Java programming was using a command shell, the javac compiler, and emacs.  I mentioned in a job interview once and the interviewer was clearly blown away.  IDEs are nice, but hardly necessary.) 

Not as elegant as redirecting stdout:

System.setOut(new PrintStream(new FileOutputStream("output.txt")));
System.out.println("This is test output");


Rick C said...

See this Stack Overflow answer:

jdege said...

I've fought with Eclipse many times, and have pretty much given up trying.

Have you tried VS Code?

Clayton Cramer said...

I followed those instructions and the required fields did not appear. There may be a settings field required to make it appear. I solved the problem another way.

Rick C said...

Strange--I hadn't tried it out before but I just did and it worked. (the instructions, now that I tried them, are...spare.)

I chose Run | Run Configurations from the menu, picked the Common tab on the right, and down near the bottom there was a checkbox next to the text "Output File:", with a textbox to the right. To get it to work I couldn't just type in a file name, I had to click the File System button and type a file name in the standard Windows File Save dialog. I also had to check the checkbox. (I see there's an Append checkbox below that, but I didn't check it--without it, it empties the file on each run.)

I tried Eclipse 2020-03 and 4.5.2.

Clayton Cramer said...

Thanks Rick. I did not scroll far enough down in that window.