'Java writing in the node.exe console window

I need help writing to the Node.exe console in Java.

I am currently using a ProcessBuilder to open up the process then I need to write in the console with a separate step.

Step 1 looks like this which works fine:

ProcessBuilder b = new ProcessBuilder("node.exe","/c");
b.redirectErrorStream(true);
Process p = builder.start();
p.waitFor();

Step 2 which is where I need help:

 Runtime.getRuntime().exec(new String[]{"node.exe" + "some text"});

One issue is that many items of node can be running at one time and I use a command line piece of code to get that PID with the first step.

But all I need to do is write text in that command window above, which will be the last process of node that was made.

How I can write a simple line of text in that command window in the screen shot?

I added this but it still does not work

OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
PrintWriter writer = new PrintWriter(stdin);
writer.write("test");
writer.flush();
stdin.close();
System.out.print(reader.read());


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source