0

端末にゲージを表示する簡単な 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;
}

しかし、それは「ダイアログ」でのみ機能し、「ホイップテール」では機能しません:(

何か助けて??

Brad S.が説明する解決策 、速すぎる場合... usleep(100000) に変更するとうまくいきました

4

1 に答える 1