0

I have run an octave script from Java using

ProcessBuilder pb = new ProcessBuilder("./ProcessImg");
Process p = pb.start();

But after executing these statements, the program isn't waiting for the process to finish and comeback.

How do I make the program wait for it? I want to use the file spit out by that script.

Currently I am running the program twice, so that first time it creates the files and also an exception,the second time the program uses the previously created file.

Tarun Maganti
  • 3,076
  • 2
  • 35
  • 64
  • 2
    `Process#waitFor` - but you'll probably also want to drain the process `OutputStream` as this can stall some process's and stop them from working, [for example](http://stackoverflow.com/questions/35713856/run-exe-by-java-process-get-error-code-109/35714130#35714130) – MadProgrammer Jan 25 '17 at 04:30
  • What do you mean by drain the process? – Tarun Maganti Jan 25 '17 at 04:53
  • Sorry, it should be "process's". Basically, you need to read the `InputStream` exposed by `Process`, otherwise it's possible that the process's output stream will get filled and the process may stall (and never end) – MadProgrammer Jan 25 '17 at 05:01
  • There is absolutely no reason, that this question has an "octave" tag, right? – Andy Jan 25 '17 at 10:07
  • Actually the file I was running was octave. Anyway, I removed the tag. – Tarun Maganti Jan 25 '17 at 12:20
  • Why did this question get a -1? Is it not a genuine problem? – Tarun Maganti Jan 25 '17 at 12:21

0 Answers0