c - C 型鞭尾压力表

标签 c linux bash whiptail

这是一个简单的 bash 代码,用于在终端中显示仪表:

#!/bin/bash
{
for ((i = 0 ; i <= 100 ; i+=5)); do
    sleep 0.1
    echo $i
done
} | whiptail --gauge "Please wait while we are sleeping..." 6 50 0
# you can replace 'whiptail' with 'dialog', it will work.

我想在 C 中重现同样的事情。因此我这样做:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

// set DIALOG to "dialog" or "whiptail"
#define DIALOG "whiptail"

int main()
{
    FILE* pipe;
    if( (pipe = popen(DIALOG " --gauge 'Loading...' 6 50 0","w") )!=NULL)
    {
        int i;
        for (i=1; i<=100; i++)
        {
            usleep(0.1);
            fprintf(pipe, "%d\n",i);
            fflush(pipe);
        }
        pclose(pipe);
    }
    return 0;
}

但它只能与“dialog”一起使用,我无法让它与“whiptail”一起使用:(

有什么帮助吗?

解决方案Brad S.解释一下,如果太快了...更改为 usleep(100000) 就可以了

最佳答案

如果我 sleep 时间更合理,它对我有用......尝试:usleep(100000);

关于c - C 型鞭尾压力表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27335514/

相关文章:

c - stm32同时adc读取

c++ - 库函数的新实现并在其中调用旧实现

linux - Docker-compose - mongodb 无法通过身份验证

c - 系统调用和中断的实现有何不同?

c - c程序删除字符串中重复的单词

c++ - C 函数调用 C++ 成员函数 - C 代码是用 C 编译器编译的

c++ - 大型 PCIe DMA Linux x86-64

linux - Bash 中有效标识符(例如函数、变量等)的规则是什么?

arrays - Shell:如何在遍历数组时附加前缀?

linux - 用于在具有索引的文件中查找唯一值的 bash 脚本