# Showing dot each second until the script ends

**URL:** <https://www.ruby-forum.com/t/showing-dot-each-second-until-the-script-ends/174136>\
**Category:** Ruby\
**Created:** [August 21, 2009, 9:16am UTC](https://www.ruby-forum.com/t/showing-dot-each-second-until-the-script-ends/174136 "2009-08-21T09:16:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [August 21, 2009, 9:16am UTC](https://www.ruby-forum.com/t/showing-dot-each-second-until-the-script-ends/174136/1 "2009-08-21T09:16:48Z")

</div>

I have a ruby script, which takes about 20 seconds to execute.

I want to show a dot (.) sign each second.

I think I need to use “sleep” method and a loop,  
but I don’t know how to add the functionality to my script.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [August 21, 2009, 9:17am UTC](https://www.ruby-forum.com/t/showing-dot-each-second-until-the-script-ends/174136/2 "2009-08-21T09:17:59Z")

</div>

On Fri, Aug 21, 2009 at 3:35 PM, Hunt J.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a ruby script, which takes about 20 seconds to execute.
> 
> I want to show a dot (.) sign each second.
> 
> I think I need to use “sleep” method and a loop,  
> but I don’t know how to add the functionality to my script.
> 
> Any help would be appreciated.

If you want to do that I think you would need a thread for that purpose.  
Does your script now print nothing for that 20 seconds?

If so, you could print a dot after each step of your program finishes.  
Then when you see the last dot, it will be finished, whether it took  
19 seconds or 22 seconds, or whatever.  
Just a suggestion.

(0…3\_000\_000).to\_a #Fake busy time  
print “.”  
STDOUT.flush

(0…3\_000\_000).to\_a #Next process, etc.  
print “.”  
STDOUT.flush

(0…3\_000\_000).to\_a  
print “.”  
STDOUT.flush

(0…3\_000\_000).to\_a  
print “.”  
STDOUT.flush

puts

Harry

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [August 21, 2009, 9:18am UTC](https://www.ruby-forum.com/t/showing-dot-each-second-until-the-script-ends/174136/3 "2009-08-21T09:18:34Z")

</div>

2009/8/21 Hunt J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I have a ruby script, which takes about 20 seconds to execute.
> 
> I want to show a dot (.) sign each second.
> 
> I think I need to use “sleep” method and a loop,  
> but I don’t know how to add the functionality to my script.
> 
> Any help would be appreciated.

Here’s one way: create a separate thread that loops infinitely and  
does the sleeping and printing.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [August 21, 2009, 9:53am UTC](https://www.ruby-forum.com/t/showing-dot-each-second-until-the-script-ends/174136/4 "2009-08-21T09:53:41Z")

</div>

Thanks. It woked fine. I just made the following:

Thread.new do

# code rhe

end
