'BufferedWriter throwing NullOutputStream on write

I create a new ProcessBuilder as:

ProcessBuilder pb = new ProcessBuilder("java", "-Xmx1G", "-classpath", "<path_to_class>", "<class_name>");

pb.directory(new File(<insert_directory>));
pb.redirectErrorStream(true);
pb.environment().put("PATH","<env_path>");

Process p = pb.start();

Downstream a bit, I run:

Process p = Runtime.getRuntime().exect(<command>);
BufferedWriter input=new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
BufferedReader output=new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader error=new BufferedReader(new InputStreamReader(p.getErrorStream()));

input.write(<string>);

I can write to the output and error BufferedReaders. But I keep getting java.io.IOException: Stream closed on ProcessBuilder$NullOutputStream.write

Other solutions have suggested getting rid of .redirectIO(), but I'm not using that here.

I can comment out the failing input section and the rest of the code executes as expected.

Any suggestions?



Sources

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

Source: Stack Overflow

Solution Source