BufferedReader 和 process.getOutputStream()

发布于 2024-12-17 13:44:19 字数 563 浏览 4 评论 0原文

我只是想在 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());

我只是希望能够逐行读取进程的输出。我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甩你一脸翔 2024-12-24 13:44:20
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);
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);
一绘本一梦想 2024-12-24 13:44:20
BufferedReader in
   = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader in
   = new BufferedReader(new InputStreamReader(process.getInputStream()));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文