我只是想用 Java 执行一个进程,所以
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());
我只是希望能够逐行读取流程的输出。我该怎么做呢?
最佳答案
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);
关于java - BufferedReader 和 process.getOutputStream(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8236852/