Java+Eclipse: how do you debug a java program that is receiving piped/redirected stdin?

Run your app, with the pipe, on the command line but add JVM args for remote debugging, like this:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044

suspend=y will tell the JVM to not actually run the program until the debugger is attached.

Next, go into the Eclipse debug launch configurations (Run -> Debug Configurations...) and create a "Remote Java Application" to connect to your app. Run the launch in Eclipse (after setting some breakpoints) and you should be able to debug. Not terribly convenient, but if you can't reproduce your issues without the pipe, this is an option.


If I'm interpreting your question right, I believe you just want to know how to send input across standard in and debug through it in eclipse.

If it's simple input, you can actually manually enter System.in data via the eclipse Console window while the program is running. Just start typing in the console window, and press enter to send the text to Standard in.

If it's something more complicated, I'd suggest abstracting the read you're trying to do to take an InputStream. In your program, you can send System.in as the InputStream. To Debug, you can send any other InputStream. For example, you could put your input in a file, and pass a FileInputStream to the method to test it.

EDIT: Without seeing some more code, I'm not sure, but you might be on to something with eof detection. A FileInputStream has a defined end of file, but I'd guess System.in has nothing of the sort. Your reader might just be waiting to read the next character and never advancing. You might have to manually stop the read after you know you've read "enough".