2

This is essentially what I'm doing:

ProcessBuilder pb = new ProcessBuilder("./myProgram","myArguments");
pb.redirectInput(new File("myFile.txt"));
try
{
    Process p = pb.start();
}
catch (Exception e)
{
    ...
}

I'm using JDK 8 at home and this code snippet works just fine. However, this is part of a school assignment and unfortunately the school is running JDK 6, so methods like redirectInput() don't exist in the ProcessBuilder class.

Is there any way I'd be able to redirect input the same way that redirectInput() does? I've been searching various solutions that people with similar problems were offered but have yet to find a working one.

Thanks!

Jon
  • 21
  • 2
  • possible duplicate of [Process requires redirected input](http://stackoverflow.com/questions/2969766/process-requires-redirected-input) – dbank Mar 23 '15 at 06:17
  • I think this is what you want: http://stackoverflow.com/a/2969981/4595816 – dbank Mar 23 '15 at 06:17
  • Also see tremendows' comment on that answer. – dbank Mar 23 '15 at 06:18
  • @dbank Thank you, the answer that you posted worked. I tried that before when I came across it while searching for an answer, but it wouldn't work until I changed it a tiny bit. In his solution, he forgot to close the OutputStream, so adding a "pos.close();" after the "fis.close();" made it work! – Jon Mar 23 '15 at 21:06

0 Answers0