Ask a Question related to Ruby, Design and Development.
-
T. Onoma #1
can't flush print when download open-uri
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
T. Onoma Guest
-
Why does word copy appear when I print a pdfmanual (download from Canon)
Every page has the word copy printed on top of the words. Can this be turned off? -
way to download AND open a PDF from within a PDF 'contents page'?
I'm not even sure if this is possible.... i'm just assuming. I have core 'contents pages' for a large technical document (distributed via CD). I... -
Can't print anything after download
have windows xp sp1 home. Just downloaded free 30 trial of adobe 6.0 professional. Now my printere will not work. I have an epson which is connected... -
download via header using flush()?
hi, i'm looking for a possibility to start a download. here is my current code: header("Content-Type: $_contenttype");... -
Download vs. Open
Is it the same client? "Larry Gillstrom" <lgillstrom@dccnet.com> wrote in message news:ugZmIfSSDHA.1912@TK2MSFTNGP12.phx.gbl... -
Robert Klemme #2
Re: can't flush print when download open-uri
Maybe it's because you didn't terminate with "\n".
"T. Onoma" <transami@runbox.com> schrieb im Newsbeitrag
news:E1AJs2a-0004hd-RA@odie.runbox.com...$stdout as well as the source_file_io, but that doesn't work either.> I'm confused. why won't this print? I tried flushing the $defout and
I'd try $defout.sync=true then you don't need the flushes.
did you mean> # 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"
print "#{source_file_io.pos}KB/#{@source_size}KB\n"
?
> end
> rescue
> puts "#{location} failed"Closing here is superfluous since "ensure" takes care of that.> remote_file.close unless remote_file.nil?
> source_file_io.close unless source_file_io.nil?
superfluous as well.> next # try next location
superfluous as well.> else
> puts ' Done.'
> break # we got it
In the end we get much cleaner code:> ensure
> remote_file.close unless remote_file.nil?
> source_file_io.close unless source_file_io.nil?
> end
> end
require 'open-uri'
# download
$defout.sync = true
prioritized_locations.each do |location|
begin
File.open(self.source_path,'w') do |source_file_io|
open(location) do |remote_file|
while incoming = remote_file.read(512)
source_file_io.write(incoming)
print "#{source_file_io.pos}KB/#{@source_size}KB "
end
end
end
rescue => e
$stderr.puts "#{location} failed: #{e}"
else
puts 'Done.'
end
end
This works for me - and does print.
robert
Robert Klemme Guest
-
T. Onoma #3
Re: can't flush print when download open-uri
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
>
>T. Onoma Guest
-
Bill Kelly #4
Re: can't flush print when download open-uri
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.
>Have you tried stdout.sync = true ?>> > 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
--------------------------------------------------------------- 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
Bill Kelly Guest
-
T. Onoma #5
Re: can't flush print when download open-uri
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
>
> -t0T. Onoma Guest
-
T. Onoma #6
Re: can't flush print when download open-uri
> Have you tried stdout.sync = true ?
Yep. Dosen't work either. Thanks though. Boy is this frustrating. There must be a simple way to do this.
P.S. SORRY ABOUT THE MULTIPLE POST. MAIL SERVER ACTING UP.
T. Onoma Guest
-
Bill Kelly #7
Re: can't flush print when download open-uri
From: "T. Onoma" <transami@runbox.com>
Hmm... Well I only have a bunch of questions then :)>>> > Have you tried stdout.sync = true ?
> Yep. Dosen't work either. Thanks though. Boy is this frustrating.
> There must be a simple way to do this.
What platform are you running on? What ruby version? Is this
a standalone script, or is it called from some other process (such
as a CGI script called by Apache)?
Do you eventually see any of your printouts at all? That is, if
a linefeed is eventually printed, do all the "buffered" prints
eventually show up?
Also, in:Do you really want a control-A? And is the sharp sign really> # THIS WON'T THIS PRINT!!!!!!!!!!!
> print "\ca{source_file_io.pos}KB/#{@source_size}KB"
ommitted there before the open brace at \ca{ ?
Regards,
Bill
Bill Kelly Guest
-
Gregory Millam #8
Re: can't flush print when download open-uri
Received: Fri, 14 Nov 2003 10:30:45 +0900
And lo T. wrote:
STDOUT.flush> > (snip)
> > source_file_io.write(incoming)
> > # THIS WON'T THIS PRINT!!!!!!!!!!!
> > print "\ca{source_file_io.pos}KB/#{@source_size}KB"> > end
> > rescue
> > (/snip)Gregory Millam Guest
-
Gavin Sinclair #9
Re: can't flush print when download open-uri
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
Gavin Sinclair Guest
-
T. Onoma #10
Re: can't flush print when download open-uri
> From: "T. Onoma" <transami@runbox.com>
linux, 1.8, standalone> What platform are you running on? What ruby version? Is this
> a standalone script, or is it called from some other process (such
> as a CGI script called by Apache)?
when the while loop finishes it all comes flying out. have tried flush on stdout and file's io.> Do you eventually see any of your printouts at all? That is, if
> a linefeed is eventually printed, do all the "buffered" prints
> eventually show up?
typo, ctrl-a i had hoped would move to beginning of line, but can't test obviously. i have since replaced this line with a call to Ruby/ProgressBar from RAA. but it still the same problem.> Also, in:>> > # THIS WON'T THIS PRINT!!!!!!!!!!!
> > print "\ca{source_file_io.pos}KB/#{@source_size}KB"
> Do you really want a control-A? And is the sharp sign really
> ommitted there before the open brace at \ca{ ?
thanks,
-t0
T. Onoma Guest
-
nobu.nokada@softhome.net #11
Re: can't flush print when download open-uri
Hi,
At Fri, 14 Nov 2003 11:01:56 +0900,
Gavin Sinclair wrote:"\c" means Control key modifier, that is "\ca" is equivalent to> BTW, what does print "\ca{source_file_io.pos}" achieve? Specifically,
> the "\ca".
"\001".
$ ruby -e 'print "\ca"'|od -tx1
0000000 01
0000001
--
Nobu Nakada
nobu.nokada@softhome.net Guest



Reply With Quote

