[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: can't flush print when download open-uri

T. Onoma

11/14/2003 1:05:00 AM

no one responded to this and i still can't get it to work. please help. let me rephrase very simply:

downloading file with open_uri and can't flush print to report download progress.

thanks,
-t0


> I'm confused. why won't this print? I tried flushing the $defout and $stdout as well as the source_file_io, but that doesn't work either.
>
> # download
> prioritized_locations.each do |location|
> begin
> source_file_io = File.open(self.source_path,'w')
> remote_file = open(location)
> while incoming = remote_file.read(512)
> source_file_io.write(incoming)
> # THIS WON'T THIS PRINT!!!!!!!!!!!
> print "\ca{source_file_io.pos}KB/#{@source_size}KB"
> end
> rescue
> puts "#{location} failed"
> remote_file.close unless remote_file.nil?
> source_file_io.close unless source_file_io.nil?
> next # try next location
> else
> puts ' Done.'
> break # we got it
> ensure
> remote_file.close unless remote_file.nil?
> source_file_io.close unless source_file_io.nil?
> end
> end
>
> -t0
>
>

3 Answers

Bill Kelly

11/14/2003 1:18:00 AM

0

Hi,

From: "T. Onoma" <transami@runbox.com>
>
> no one responded to this and i still can't get it to work. please help.
> let me rephrase very simply:
>
> downloading file with open_uri and can't flush print to report download progress.
>
[...]
>
> > while incoming = remote_file.read(512)
> > source_file_io.write(incoming)
> > # THIS WON'T THIS PRINT!!!!!!!!!!!
> > print "\ca{source_file_io.pos}KB/#{@source_size}KB"
> > end

Have you tried stdout.sync = true ?

--------------------------------------------------------------- IO#sync=
ios.sync = aBoolean -> aBoolean
------------------------------------------------------------------------
Sets the ``sync mode'' to true or false. When sync mode is true,
all output is immediately flushed to the underlying operating
system and is not buffered internally. Returns the new state. See
also IO#fsync.
f = File.new("testfile")
f.sync = true
(produces no output)


Hope this helps,

Bill



Gavin Sinclair

11/14/2003 2:02:00 AM

0

On Friday, November 14, 2003, 12:05:16 PM, T. wrote:

> no one responded to this and i still can't get it to work. please help. let me rephrase very simply:

> downloading file with open_uri and can't flush print to report download progress.

>> [snip]

>> # THIS WON'T THIS PRINT!!!!!!!!!!!
>> print "\ca{source_file_io.pos}KB/#{@source_size}KB"



I doubt it has anything to do with open-uri. Try STDOUT.flush after
the print.

BTW, what does print "\ca{source_file_io.pos}" achieve? Specifically,
the "\ca".

Gavin


nobu.nokada

11/17/2003 2:13:00 AM

0

Hi,

At Fri, 14 Nov 2003 11:01:56 +0900,
Gavin Sinclair wrote:
> BTW, what does print "\ca{source_file_io.pos}" achieve? Specifically,
> the "\ca".

"\c" means Control key modifier, that is "\ca" is equivalent to
"\001".

$ ruby -e 'print "\ca"'|od -tx1
0000000 01
0000001

--
Nobu Nakada