-   Programming (
-   -   dialog command buffering problem in pipe (

yamanoorsai 08-23-2012 07:08 AM

dialog command buffering problem in pipe
I am trying to pipe percentage values into pipe by the following methods:


rsync -a --progress ~/Desktop/test.tar.gz ~/Downloads |
        unbuffer -p grep -o "[0-9]*%" |
        unbuffer -p cut -f1 -d '%'|
        dialog --title "Test" --gauge "Copying file. " 6 100

If you try to copy a file from a DVD, the dialog screen is reset every time and the screen just shows 0%.

I am trying an alternative:

dialog --title "Test" --gauge "Copying file." 6 100 <<< "$(
        rsync -a --progress ~/Desktop/version-000.tar.gz ~/Downloads |      unbuffer -p grep -o "[0-9]*%" |
        unbuffer -p cut -f1 -d '%' 

The alternative method is buffering the data and I am not able to display the data immediately. Are there alternatives?

414N 08-23-2012 07:25 AM

I came across a similar problem when trying to put an mencoder/ffmpeg video conversion progress inside a dialog gauge widget.
You can try it this way (warning: the following script needs polishing):

rsync  -aP FILE  DEST | while read -d $'\r' INFO
        #Retrieve progress %
        progress=$(echo "$INFO" | awk '{print $2}')
        #Remove trail %
        #Pass the progress % to dialog
        echo $progress | dialog --title "Insert a title here" --gauge "Insert some useful text here" 6 100

You'll extract a wrong progress indicator on the first lines of rsync output, but that can be mitigated with appropriate checks on the progress variable.

All times are GMT -5. The time now is 03:02 PM.