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

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -