dtnat80842 2018-05-24 12:56
浏览 60
已采纳

在CLI中使用进度条[重复]

This question already has an answer here:

I have code which execute npm install as below:

cmd := exec.Command("npm", "install")

and it finish with

if err = cmd.Wait(); err != nil {
    logs.("Error running %s: %v
", cp[1:], err)
    return err
}

I want to use progress bar and I've found the following https://github.com/cheggaaa/pb but since I dont control the time of the execution ( I dont know when it finish), how can I use it ?

UPDATE

Since we cannot calculate the time that will take (it depends on network etc) so I just want to show that something is working, show that the process is running ,since the user wait 20 sec and he think that nothing working, how it can be done?

</div>
  • 写回答

1条回答 默认 最新

  • douzhang5984 2018-05-24 13:48
    关注

    The very short answer is: you can't if you don't have any indicative units.

    The slightly longer answer: Providing feedback to the user can be done in several ways. If you don't have granular progress information (E.g.: n out of 10 steps has been completed or n out of 10 seconds have passed), you can't really show a meaningful progress bar.

    You can provide the user with feedback about what's happening. This is, however, something npm already does so why not just show that output instead?

    If you only care about showing a progress bar regardless of how meaningful it might be, what you could do is guesstimate how much time the process is going to take. Simply time it once and use that as a point of reference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”