Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make an input to an started process with ProcessBuilder?

We have a closed-source archive that does only one thing: reads a string input and outs its value hashed. Not by its command arguments, but once it is started and stays continuously open, getting inputs and giving the value properly hashed.

So I want to open it with ProcessBuilder and do the inputs. The problem is that i have tried to input in the process and i have failed:

ProcessBuilder pb = new ProcessBuilder("/path/to/executable");
Process p = pb.start();
OutputStream os = p.getOutputStream();
PrintWriter pw = new PrintWriter(os);
pw.write("Hey\n");
String result = read(p);
System.out.println("Out: " + result);
p.destroy();

But looks like i’m not getting any output, first of because the executable is not getting my "Hey".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So the main question is, how do I input into the started program? Any kind of suggestions are welcome.

>Solution :

After

pw.write("Hey\n");

Try doing a

pw.flush(); 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading