SyntaxFix
Write A Post
Hire A Developer
Questions
You have writer.close(); in your code. So bash receives EOF on its stdin and exits. Then you get Broken pipe when trying to read from the stdoutof the defunct bash.
writer.close();
stdin
Broken pipe
stdout