如何检查进程的进度

发布于 2024-10-15 12:44:09 字数 114 浏览 0 评论 0原文

我使用 java 开发了一个独立的应用程序,在其中使用运行时执行外部进程。但该过程的执行需要很多时间,我想显示它的进度监视器。

如何获取已使用 Java 运行时执行的进程的进度?我应该使用进度条吗?

I have developed a standalone application using java, in which I am executing an external process using Runtime. But the execution of that process takes much time, and I would like to display a progress monitor of it.

How can I get the progress of a process that has been executed using Java runtime? Should I use a Progress Bar?

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

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

发布评论

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

评论(4

不及他 2024-10-22 12:44:09

为了能够“了解”流程的进度,您将需要实现流程随着进展而变化的某种里程碑。您必须实现该逻辑,以便外部进程将其进度通知您的应用程序。然而,这并不总是可能的(因为,首先您需要访问外部进程的代码)或容易做到。

您可以做的是使用选框进度条,这将使动画无限期地进行:

有时你不能立即
确定长时间运行的长度
任务,否则任务可能会停留在
相同的完成状态
很久。您无需展示作品即可
通过将可衡量的进展
不确定模式下的进度条。一个
不确定模式下的进度条
显示动画来表明
工作正在进行。

您可以查看这个 Java 教程(来自同一位置)我从哪里得到了上面的文字)以获取更多信息。

To be able to 'know' the progress of the process, you will need to implement some sort of milestones that the process changes as it goes along. You will have to implement that logic so that the external process notifies your application of its progress. However, this is not always possible (because, first of all you need access to the code of the external process) or simple to do.

What you can do, is to use a Marquee Progress bar, this will keep an animation going indefinitevely:

Sometimes you can't immediately
determine the length of a long-running
task, or the task might stay stuck at
the same state of completion for a
long time. You can show work without
measurable progress by putting the
progress bar in indeterminate mode. A
progress bar in indeterminate mode
displays animation to indicate that
work is occurring.

You can take a look at this Java tutorial (same place from where I got the above text) for more information.

高跟鞋的旋律 2024-10-22 12:44:09

您必须与外部进程通信才能获取其状态。如果外部进程不提供任何有关其状态的信息,您就无法完成您想要的任务。

You have to communicate with the external process to get its status. If the external process does not provide anything about its status, you could not accomplish what you want.

孤城病女 2024-10-22 12:44:09

这只能通过读取进程的输出流(myProcess.getInputStream() 和 myProcess.getErrorStream())来实现,当然只有进程在输出上显示其进度时才可能。

有些进程仅在认为自己正在交互式 shell 中运行时才显示进度,因此您必须通过传递相应的环境参数来“模拟”shell(wget 是这些工具之一)。

当然,您必须手动解析进程的输出。

如果您的外部进程包括将数据从一个命令传输到另一个命令,则可以使用 pv(1) 命令,显示输出。

This is only possible by reading from the process's output streams (myProcess.getInputStream() and myProcess.getErrorStream()), and of course only if the process displays its progress on the output.

There are processes that only display progress when they believe they are running in an interactive shell, so you have to "emulate" a shell by passing the corresponding environment parameters (wget is one of those tools).

Of course you have to manually parse the process's output.

If your external process includes piping data from one command to another, you can use the pv(1) command, to display the output.

梦初启 2024-10-22 12:44:09

触及核心:如果您不知道且无法控制、测量或预测事务的持续时间,请使用jProgressBar1.setIndependent(true);

To get to the core: if you do not know and can not control, measure or predict the duration of the transaction use jProgressBar1.setIndeterminate(true);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文