1

I'm trying to make a graphical utility with bash, zenity and a script written in C and there is an issue with progressbar, zenity ignores input from the C script.

For example:

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

int main(int argc, char *argv[]) {
    for (int i=0; i < 11; i++) {
        printf("%d\n", i*10);
        sleep(1);
    }
}

A bash version of the same:

for (( i=0; i < 11; i++ )); do
    echo $(( i*10 ))
    sleep 1
done

This will give the same result in a terminal: 0,10,20..100 separated by a new line. But zenity will take it from echo and won't take it from printf. Why?

That's how I use zenity with C scripts:

gcc -o pp pp.c # C script from above

./pp | zenity --progress --auto-close

And how I use it with bash:

(for ((i=0; i<11; i++)); do echo $(( i*10 )); sleep 1; done) | zenity --progress --auto-close

I even tried to replace echo by printf in bash:

printf "%d\n" $(( i*10 ))

It also works fine.

0 Answers0