LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2013, 02:18 PM   #1
defila
LQ Newbie
 
Registered: Aug 2013
Posts: 14

Rep: Reputation: Disabled
loop with zenity - why is progress bar failing?


Hello guys,

I do have a little issue with my pseudo code. I am trying to copy files from one place to another and show the progress bar of the task, however the progress will start on 0% and change its GUI to 100% immediately (there is no progress on the bar), files were copied to desired location, I did not have issue with that.

Do you have any advice?

PSeudo code
Code:
#!/bin/bash

cd ~
for file in *.txt
do
echo "$file"
cp ${file} ~/test
sleep 0.1
done | zenity --progress --title="TXT" --text="uploading" --percentage="0"
 
Old 08-18-2013, 03:58 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
pseudo-answer?
Code:
do_work ()
{
	cd ~
	for file in *.txt
	do
	echo "$file"
	cp ${file} ~/test
}

touch /tmp/$$
( ( echo 1 ; while [ -f /tmp/$$ ] ; do sleep 1 ; done ; echo 100 ) | zenity --progress --undecorated --no-buttons) & do_work
rm /tmp/$$
make the work a function, write a /tmp/$$ file ; while /tmp/$$ file exists; do work, then rm /tmp/$$

This "borrows" on The following example script shows how to create a progress dialog

"Stolen" from here...
I tried using zenity progress also at that link but I never could get a progress to show progress incrementally, so I just used yad (a zenity fork with more options) with a pulsate option instead.

References:
http://gnome-look.org/content/show.p...content=104818


Hope that helps...

Oh yeah,
Welcome to LQ.

Last edited by Habitual; 08-18-2013 at 03:59 PM.
 
Old 08-19-2013, 02:24 AM   #3
defila
LQ Newbie
 
Registered: Aug 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thanks for answer
quite clever way howto solve it. Anyway, I tried to execute it and will receive "error near unexpected token `}' "
I tried to play with it to find out if it is not executing some additional space e.g. like this:
Code:
dowork () {
	cd ~
	for file in *.txt
	do
	echo "$file"
	cp ${file} ~/test \
}
but then I will face "unexpected end of file". Did I miss something here?

is there any
 
Old 08-19-2013, 07:21 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
defila:

Try this instead:
Code:
dowork () {
	cd ~
	for file in *.txt 
	do cp ${file} ~/test
        done
}
I'm guessing the "echo" was for a visual verification during "construction" of the program/routine?

subscribed with interest...

Last edited by Habitual; 08-19-2013 at 07:24 AM.
 
Old 08-19-2013, 07:26 AM   #5
defila
LQ Newbie
 
Registered: Aug 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hah! I have find 'dull' workaround for it :}
I have created a function and send the output into zenity
Code:
.....
2>&1 | zenity --progress --auto-close --pulsate --title "Whatever"
.....
files are copied to location and it seems that the progress bar is reflecting the action (for the user) (--pulsate option does not really show the progress but since the output is redirected into zenity it will end automatically as it will finish)
it is not clever solution but it will help me now
hopefully nobody will read the pseudo-script :}}
 
Old 08-19-2013, 07:37 AM   #6
defila
LQ Newbie
 
Registered: Aug 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
defila:

Try this instead:
Code:
dowork () {
	cd ~
	for file in *.txt 
	do cp ${file} ~/test
        done
}
I'm guessing the "echo" was for a visual verification during "construction" of the program/routine?

subscribed with interest...
Hi,
yes, it was for verification and your version works as well, thanks :}
 
Old 08-19-2013, 09:41 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Glad it worked out!
some other yad|zenity tips at http://www.bournetoraiseshell.com/in...opic=YadZenity
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Openbox setup - help with Zenity --progress creeper3d Programming 1 04-30-2013 11:48 AM
Zenity progress bar mard0 Programming 3 09-22-2012 02:19 PM
converting a for loop to an array so zenity can give progress wonderfullyrich Programming 2 03-01-2012 08:58 AM
[SOLVED] progress bar instead of % complete in my for loop genderbender Programming 14 11-26-2010 09:35 AM
Problem with combining bash with zenity --progress chii-chan Programming 2 05-06-2005 03:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration