多个进度条
除了我之前关于 shell 脚本中的多线程的查询之外,我很好奇是否可以有多个进度条。
这是我预期结果的代码片段:
Output : 1 of 100 Files Completed # Thread1
Output : 10 of 45 files Completed # Thread 2
这些行已更新,显示进度。可以在shell中实现吗?
In addition to my previous query concerning multi-threading in shell scripting, I am curious if its possible to have multiple progress bar.
Here is a code snippet of my expected result :
Output : 1 of 100 Files Completed # Thread1
Output : 10 of 45 files Completed # Thread 2
The lines are updated showing the progress. Would it be possible to implement it in shell?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的子进程输出是可过滤的,那么您可以将每个子进程的标准输出重定向到不同的文件描述符,然后调用一个函数来循环该文件描述符的输出。然后您可以尝试使用 printf 来更新进度表。但这就是你会遇到麻烦的地方。不确定 Bash 的内置 printf 是否可以处理终端的细节。我从未尝试过在 Bash 中编写一个进行多行输出的进度表。为什么不使用对话框?
If your subprocess output is filterable then you can redirect stdout of each subproc to a different file descriptor and then call a function to loop through that file descriptor's output. Then you can try to use printf to update the progress meter. This is where you will run into trouble though. Not sure Bash's builtin printf can handle the terminal to that detail. I never tried to write a progress meter in Bash that does multi-line output. Why not use dialog?
是的,这很有可能。
假设您现有的代码(基于您之前的帖子)当前是这样的:
...那么您可以执行以下调整以实现您想要的效果:
Yes, it is very much possible.
Assuming that your existing code (based on your prior posts) currently goes something like this:
...then you can perform the following adjustments in order to achieve the effect that you had in mind:
就像
pv -c
所做的那样?当然,请参阅 src/pv/cursor.c 。虽然仅通过 shell 并不真正安全,但一个小型 C 实用程序可以处理它。
Like what
pv -c
does?Sure, see src/pv/cursor.c. Although it's not really safely doable from shell only, a small C utility could take care of it.