1

I want to do something along these lines.

    Process shell = Runtime.getRuntime().exec("/bin/bash");

Then I want to use the streams for the shell process to talk to the bash shell. However this doesn't seem to work at all and it totally stumps me.

I found this link which seems to talk about the same problem. Why exactly does this happen and are there better solutions than the one outlined in the link?

jetru
  • 1,964
  • 4
  • 16
  • 24

1 Answers1

2

It can be necessary to flush your writes from the JVM to the child process to make sure its getting its input. IIRC I didn't need to do this on Windows, but did on Linux. I also ran into issues where I had to force the child process to flush writes so the JVM would see them right away too.

Also, make sure that you have JVM threads reading from stdout and stderr before you do anything, if either of those buffers fills up it can lock the process. This is a huge problem on Windows. You will only need one thread if you use the options to combine the streams when launching the process.

Also, your example (above), doesn't have a newline, wouldn't bash require one? e.g. "touch blah\n"

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57