From: Dwayne.Dibbley on
i am trying to convert the following tcl script to run on a web
server, all it does is download a file from another http server and
display the progress ( in this case dots "." ) but when it runs it
only copies 4k of the file ( due to the chunk size ) then stops i am
guessing as its trying to run the -progress loop?

origional tcl:

# Copy a URL to a file and print meta-data
proc httpcopy { url file {chunk 4096} } {
set out [open $file w]
set token [::http::geturl $url -channel $out \
-progress httpCopyProgress -blocksize $chunk]
close $out

# This ends the line started by httpCopyProgress
puts stderr ""

upvar #0 $token state
set max 0
foreach {name value} $state(meta) {
if {[string length $name] > $max} {
set max [string length $name]
}
if {[regexp -nocase ^location$ $name]} {
# Handle URL redirects
puts stderr "Location:$value"
return [httpcopy [string trim $value] $file $chunk]
}
}
incr max
foreach {name value} $state(meta) {
puts [format "%-*s %s" $max $name: $value]
}

return $token
}
proc httpCopyProgress {args} {
puts -nonewline stderr .
flush stderr
}
From: Glenn Jackman on
At 2008-06-20 04:22AM, "Dwayne.Dibbley(a)gmail.com" wrote:
> i am trying to convert the following tcl script to run on a web
> server, all it does is download a file from another http server and
> display the progress ( in this case dots "." ) but when it runs it
> only copies 4k of the file ( due to the chunk size ) then stops i am
> guessing as its trying to run the -progress loop?

What do your web server's log files say? You are printing to stderr so
look at the "errors" log file. Maybe the server can't handle writing an
incomplete line to a log file.

> origional tcl:
>
> # Copy a URL to a file and print meta-data
> proc httpcopy { url file {chunk 4096} } {
> set out [open $file w]
> set token [::http::geturl $url -channel $out \
> -progress httpCopyProgress -blocksize $chunk]
> close $out
>
> # This ends the line started by httpCopyProgress
> puts stderr ""
>
> upvar #0 $token state
> set max 0
> foreach {name value} $state(meta) {
> if {[string length $name] > $max} {
> set max [string length $name]
> }
> if {[regexp -nocase ^location$ $name]} {

I'd write {[string tolower $name] eq "location"}

> # Handle URL redirects
> puts stderr "Location:$value"

Do you want to print to stdout there?

> return [httpcopy [string trim $value] $file $chunk]
> }
> }
> incr max
> foreach {name value} $state(meta) {
> puts [format "%-*s %s" $max $name: $value]
> }
>
> return $token
> }
> proc httpCopyProgress {args} {
> puts -nonewline stderr .
> flush stderr
> }


--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
From: Gerald W. Lester on
Dwayne.Dibbley(a)gmail.com wrote:
> i am trying to convert the following tcl script to run on a web
> server, all it does is download a file from another http server and
> display the progress ( in this case dots "." ) but when it runs it
> only copies 4k of the file ( due to the chunk size ) then stops i am
> guessing as its trying to run the -progress loop?

What web server?

How are you running it (CGI, ...)?

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
From: Dwayne.Dibbley on
On Jun 20, 3:25 pm, "Gerald W. Lester" <Gerald.Les...(a)cox.net> wrote:
> Dwayne.Dibb...(a)gmail.com wrote:
> > i am trying to convert the following tcl script to run on a web
> > server, all it does is download a file from another http server and
> > display the progress ( in this case dots "." ) but when it runs it
> > only copies 4k of the file ( due to the chunk size ) then stops i am
> > guessing as its trying to run the -progress loop?
>
> What web server?
>
> How are you running it (CGI, ...)?
>
> --
> +--------------------------------+---------------------------------------+
> | Gerald W. Lester                                                       |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+

Its running in a Novadigm TCL server ( now HP ) using TCL 8.2 -
nvdkit.exe httpd.tkd

above was the working tcl script

when i use it on the web page i use:

<%
# Copy a URL to a file and print meta-data
proc httpcopy { url file {chunk 4096} } {
set out [open $file w]
set token [::http::geturl $url -channel $out \
-progress httpCopyProgress -blocksize $chunk]
close $out

# This ends the line started by httpCopyProgress
write ""

upvar #0 $token state
set max 0
foreach {name value} $state(meta) {
if {[string length $name] > $max} {
set max [string length $name]
}
if {[regexp -nocase ^location$ $name]} {
# Handle URL redirects
write "Location:$value"
return [httpcopy [string trim $value] $file $chunk]
}
}
incr max
foreach {name value} $state(meta) {
write [format "%-*s %s" $max $name: $value]
}

return $token
}

proc httpCopyProgress {args} {
write .
}

set url http://blarblar.exe
set file c:/blarblar.exe
httpcopy $url $file

%>

if i remove the "-progress httpCopyProgress" it works fine but i dont
get and progress indicators

Thanks

From: Alexandre Ferrieux on
On Jun 20, 5:27 pm, Dwayne.Dibb...(a)gmail.com wrote:
>
>    set token [::http::geturl $url -channel $out \
>           -progress httpCopyProgress -blocksize $chunk]

This may be a red herring, but notice that the above, having no -
command, is synchronous, and will call [vwait] internally. Depending
on how your Tcl-enabled web server works, this may (or may not) mean a
nested vwait, which could lead to a deadlock. Avoiding this in your
specific case is not doable without further knowledge of the guts of
the server. Indeed, the semantics of what's executed inside <% %>
being "replace by result", adding a -command to the geturl will not
trivially solve the issue, because it will then return immediately at
progress 0, and later the completion callback will no longer have
"output in progress" to write to...

Bottom line: would like to see the (Tcl) source of the server...

-Alex