How to send EOF to a process in Java? -
i want run groff
in java program. input comes string. in real command line, terminate input ^d
in linux/mac. how send terminator in java program?
string usage += ".dd \\[year]\n"+ ".dt test 1\n"+ ".os\n"+ ".sh test\n"+ "^d\n"; // <--- eof here? process groff = runtime.getruntime().exec("groff -mandoc -t ascii -"); groff.getoutputstream().write(usage.getbytes()); byte[] buffer = new byte[1024]; groff.getinputstream().read(buffer); string s = new string(buffer); system.out.println(s);
or other idea?
^d
isn't character; it's command interpreted shell telling close stream process (thus process receives eof on stdin
).
you need same in code; flush , 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(); ...
Comments
Post a Comment