LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Dialog GAUGE - How to display progress of compile? broken pipe problem? (http://www.linuxquestions.org/questions/programming-9/dialog-gauge-how-to-display-progress-of-compile-broken-pipe-problem-200614/)

laikos 07-03-2004 05:52 AM

Dialog GAUGE - How to display progress of compile? broken pipe problem?
 
Hi All,
I have been working on script to compile the alsa code on my machine. I wish to create a script to wrap up the installation such that it will display progress bar using the dialog --gauge option instead of just the output.
I managed to get the dialog --gauge working using the follow script
Code:

##############################################################################
#                        display progress
##############################################################################
display_progress(){
DIALOG=dialog
echo "Display Progress"
CMD="$1"
COMPLETE="$2"
PROGRESS_TITLE="$3"
HELP_TXT="$4"
$CMD | awk '{ print $1 }' | xargs -n1 echo "$COMPLETE" | awk '{ TotalLine+=1; print ((TotalLine/$1)*100); if (TotalLine > $1) { TotalLine=$1 } }' | $DIALOG  --backtitle "$INSTALLER_TITLE" --title "$PROGRESS_TITLE" --gauge "$HELP_TXT" `expr $SCREEN_HEIGHT / 5`  $SCREEN_WIDTH
} #end display progress

I will issue a command like
Code:

display_progress "tar -jxvf alsa-driver-$ALSA_VERSION.tar.bz2" "1200" "Uncompressing ALSA DRIVER source" "Uncompressing ALSA DRIVER Source ; alsa-$ALSA_VERSION into your hard drive"
This command create a nice progress bar while the file is being uncompressed. :-)

However
When I try to use the command with cvscompile or any other script I can't get the output from that script go all the way through the pipe. It will stop at the second pipe.
That's mean
Code:

$CMD | awk '{ print $1 }'
Will produce output but
Code:

$CMD | awk '{ print $1 }' | xargs -n1 echo "$COMPLETE"
Produces nothing.

I hope anyone could explain and help with this program because it's really confusing me
Thanks in advance

Hko 07-03-2004 06:43 AM

I'm not if this helps you, but you can split a pipe in 2 by making a filesystem-pipe ("fifo") and use the "tee" program to write to the fifo while also have the same output flow donw the normal pipe line. Somthing like this:

Code:

mkfifo /tmp/my_fifo
$CMD | awk '{ print $1 }' | tee /tmp/my_fifo | xargs -n1 echo "$COMPLETE" &  #note '&': run in background.
cat /tmp/my_fifo | your_progress_bar_program


laikos 07-03-2004 11:06 AM

Thanks HKo for your reply,
It does help however I found out that there's something wrong with the update
I did this instead
[code]
export COMPLETE=1200
./cvscompile | awk '{ Total +=1; print (Total/ENVIRON["COMPLETE"])*100 }'

1
2
3
4
5
.... (steadily and sequentially
[code]

However, when I pipe in the output to the "dialog" program, I got a long pause then a suddent rush to 100%
Code:

export COMPLETE=1200
./cvscompile | awk '{ Total +=1; print (Total/ENVIRON["COMPLETE"])*100 }' | dialog --gauge "Compiling" 7 70

I'm pretty confused now

laikos 07-03-2004 08:08 PM

Hi All!
It's working. For some reason when I woke up this morning I tried this
Code:

./cvscompile 2>&1 | awk '{ print (Total+=1)/60.6,"=>",$0}' | dialog --gauge "Compiling..." 7 70
where 60.6 (is 1/10) of the total output line it will produce

I'm heading for a happy breakfast now
Thanks you guys.


All times are GMT -5. The time now is 12:39 AM.