I am trying to use zenity --progress.
When I use this script: #!/bin/sh ( echo "10" ; sleep 1 echo "20" ; sleep 1 echo "50" ; sleep 1 echo "75" ; sleep 1 echo "100" ; sleep 1 ) | zenity --progress ~
It works fine...
When I use a little program. for(count = 0; count <= 100; count += 10) { printf(stdout, "%d\n", count); sleep(1); }
and run it as "myprog | zenity --progress" I dont get anything updating until the end and the program exits.
Why does the second example not work. Both are just piping stdout into zenity. Both use carriage return.
Thanks,
Jerry
On 5/21/07 1:58 PM, "Jerry Geis" geisj@pagestation.com spake:
...
When I use a little program. for(count = 0; count <= 100; count += 10) { printf(stdout, "%d\n", count); sleep(1); } ...
Try adding this after your printf():
fflush(stdout);
The stdio functions use buffered output, so it's likely that zenity is just not getting any of the output until the program has completed. By doing an fflush() you will force the data to be flushed from the buffer and printed, so that zenity can pick it up from the pipe.
Ryan
Ryan Ordway wrote:
On 5/21/07 1:58 PM, "Jerry Geis" geisj@pagestation.com spake:
...
When I use a little program. for(count = 0; count <= 100; count += 10) { printf(stdout, "%d\n", count); sleep(1); } ...
Try adding this after your printf():
fflush(stdout);
Not going to change anything. Since stdout is by default opened as a text mode file, and is also set to be line buffered, the '\n' at the end of each line automatically causes an fflush(.) and adding another won't help.
The stdio functions use buffered output, so it's likely that zenity is just not getting any of the output until the program has completed. By doing an fflush() you will force the data to be flushed from the buffer and printed, so that zenity can pick it up from the pipe.
Well, what you say is true, but the fflush(.) is going to happen, anyway. If adding one causes a difference in behavior, then you have a non-conforming implementation (i.e., it isn't C).
Mike
On 5/21/07 1:58 PM, "Jerry Geis" <geisj at pagestation.com http://lists.centos.org/mailman/listinfo/centos> spake:
/...
/>>/ />>/ When I use a little program. />>/ for(count = 0; count <= 100; count += 10) />>/ { />>/ printf(stdout, "%d\n", count); />>/ sleep(1); />>/ } />>/... /
Try adding this after your printf():
fflush(stdout);
The stdio functions use buffered output, so it's likely that zenity is just not getting any of the output until the program has completed. By doing an fflush() you will force the data to be flushed from the buffer and printed, so that zenity can pick it up from the pipe.
Ryan
That did it... THanks so much.
Jerry