1

I'm simply trying to execute a process in Java, so

Runtime runtime = Runtime.getRuntime();
this.process = null;

try {
    this.process = runtime.exec(new String[] {
        properties.getPropertyStr("ffmpegExecutable", "/usr/bin/ffmpeg"),
        "-i", this.streamEntry.getSource(),
        "-vcodec", "copy",
        "-acodec", "copy",
        this.streamEntry.getDestination()
    });
} catch (IOException e) {
    e.printStackTrace();
    return;
}

BufferedReader stdout = new BufferedReader(???process.getOutputStream());

I simply want to be able to read the output of the process line by line. How do I do this?

Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411

2 Answers2

5
BufferedReader is;  // reader for output of process
String line;

// getInputStream gives an Input stream connected to
// the process standard output. Just use it to make
// a BufferedReader to readLine() what the program writes out.
is = new BufferedReader(new InputStreamReader(p.getInputStream()));

while ((line = is.readLine()) != null)
  System.out.println(line);
Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
2
BufferedReader in
   = new BufferedReader(new InputStreamReader(process.getInputStream()));
Gabriel Belingueres
  • 2,945
  • 1
  • 24
  • 32