LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   dialog command buffering problem in pipe (http://www.linuxquestions.org/questions/programming-9/dialog-command-buffering-problem-in-pipe-4175423593/)

yamanoorsai 08-23-2012 08:08 AM

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

Code:

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:
Code:

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 08: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):
Code:

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

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 05:45 AM.