如何让 Perl/Tk 进度条显示外部进程正在运行?
我正在创建一个 Perl/TK GUI 代码,它将在内部调用一个单独的 exe。 进度条小部件将是其中正在执行的唯一指示,但问题是,当您运行代码时,进度条会冻结,因为它必须首先完成单独 exe 的执行,完成后,进度上的活动可以更新。
有没有更好的方法可以对单独的exe同时执行进度,从而实时执行代码?
I am creating a Perl/TK GUI code that will call a seperate exe inside. The progress bar widget will be the only indication that execution is happening inside it but problem is, as you run the code, the progress bar freezes because it has to finish first the execution of the seperate exe and after it's done, activity on the progress can be updated.
Is there a better way to have a simultenous implementation of the progress with respect to the seperate exe so as to have the real time execution of the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你如何调用外部程序? 如果您阻塞了诸如
system()
之类的东西,请不要这样做。 在单独的进程中运行该程序,然后轮询以检查它是否正在运行。 只要它正在运行,您就会更新进度指示器。How are you calling the external program? If you are blocking on something like
system()
, don't do that. Run the program in a separate process then poll to check if it is running. As long as it is running, you update your progress indicator.您是否从其他进程获得进度输出? 如果是这样,您可以使用
open()
来运行你的子流程。您还应该查看 perlipc 部分perldoc.perl.org/perlipc.html#Using-open()-for-IPC" rel="nofollow noreferrer">使用
open()
进行 IPC,以及 安全管道打开Do you get output for progress from the other process? if so, you can use
open()
to run your subprocess.You should also take a look at the perlipc sections on using
open()
for IPC, and Safe pipe opens我对 Perl/Tk 的了解不够,无法快速给出一个例子。
worker.pl
boss.pl
I don't know enough Perl/Tk to whip up a quick example.
worker.pl
boss.pl