^D not a character; this is a command interpreted by your shell telling it to close the thread for the process (thus, the process receives EOF on stdin ).
You need to do the same in your code; close and close OutputStream :
String usage = ".Dd \\[year]\n" + ".Dt test 1\n" + ".Os\n" + ".Sh test\n"; ... OutputStream out = groff.getOutputStream(); out.write(usage.getBytes()); out.close(); ...
source share