# Print messages show up after script has quit

**URL:** <https://www.ruby-forum.com/t/print-messages-show-up-after-script-has-quit/92893>\
**Category:** Ruby\
**Created:** [April 25, 2007, 2:15pm UTC](https://www.ruby-forum.com/t/print-messages-show-up-after-script-has-quit/92893 "2007-04-25T14:15:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@stan](https://www.ruby-forum.com/u/stan)\
**Post date:** [April 25, 2007, 2:15pm UTC](https://www.ruby-forum.com/t/print-messages-show-up-after-script-has-quit/92893/1 "2007-04-25T14:15:46Z")

</div>

Hello,

I use ruby 1.8.6 on windows xp sp2. My script updates podcast  
subsrciptions at night.This saves internet traffic during the day. It  
starts iTunes application, sleeps while itunes updates feeds and then  
quits.

Here’s listing

require ‘win32ole’

#starts itunes application and updates podcasts  
ready = Time.local(2007, “Apr”, 25, 15, 05, 1)  
done = false  
while !done do

now = Time.now

if now \> ready then  
itunes = WIN32OLE.new(‘iTunes.Application’)  
if itunes then  
print “Update started\n”  
itunes.UpdatePodcastFeeds  
sleep 30 # waits 30 secs

```
  itunes.Quit
  print "shutdown...\n"
  done=true
end

```

else  
print “Not so fast boy…” + now.to\_s() + “\n”  
sleep(30) # waits for 30 secs  
end  
end

While testing I noted that any debug output I print shows up in a  
window after the applicaiton has quit. I don’t know why it is  
happening, because obviously I want script to print messages to see  
its activity. Any help appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![stan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@stan](https://www.ruby-forum.com/u/stan)\
**Post date:** [April 25, 2007, 2:38pm UTC](https://www.ruby-forum.com/t/print-messages-show-up-after-script-has-quit/92893/2 "2007-04-25T14:38:55Z")

</div>

> Hello,
> 
> I use ruby 1.8.6 on windows xp sp2. My script updates podcast  
> subsrciptions at night.This saves internet traffic during the day. It  
> starts iTunes application, sleeps while itunes updates feeds and then  
> quits.

This is happening because stdout is buffered.

Text written to stdout will appear once the buffer is full, when the  
program ends or if you ask for the buffer to be flushed by calling  
$stdout.flush like this:

> else  
> print “Not so fast boy…” + now.to\_s() + “\n”  
> $stdout.flush # flush stdout  
> sleep(30) # waits for 30 secs  
> end

Kristian
