Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Executing curl from a tcl script

2,110 views
Skip to first unread message

hresquiveloa

unread,
May 25, 2010, 10:54:05 AM5/25/10
to
Hi. Can anyone help me to understand why the script shown below will
not work as expected?

foreach line {CAPEMEND/FOR-UP.AT2 CAPEMEND/FOR000.AT2 CHICHI/CHY025-
W.AT2} {
exec bash -c "curl -O http://peer.berkeley.edu/smcat/data/ath/$line"
}

The script goal is to download a set of files (accelerograms) from the
PEER Strong Motion Database... Thank you!

Fandom

unread,
May 25, 2010, 11:01:30 AM5/25/10
to
Try:

foreach line {CAPEMEND/FOR-UP.AT2 CAPEMEND/FOR000.AT2 CHICHI/CHY025-
W.AT2} {

exec curl -O http://peer.berkeley.edu/smcat/data/ath/$line

}

You don't need 'bash -C' and if you put the curl command between
commas
exec will consider it a single 'word', not a command with parameters.

Andres

hresquiveloa

unread,
May 25, 2010, 11:09:03 AM5/25/10
to
Andres, thank you for reply.

It is still not working... I mean, it just download the first file...
any idea?

Thank you!

scottdware

unread,
May 25, 2010, 11:39:00 AM5/25/10
to

You could try:

foreach line {CAPEMEND/FOR-UP.AT2 CAPEMEND/FOR000.AT2 CHICHI/CHY025-
W.AT2} {

exec {*}[auto_execok curl] -O http://peer.berkeley.edu/smcat/data/ath/$line

}

And see if that works...

hresquiveloa

unread,
May 25, 2010, 11:55:16 AM5/25/10
to
Neither.

I am thinking of rewriting all the script I made in Tcl using fully
bash syntax... I think it is more straightforward that way.

Thank you scottdware...

Alexandre Ferrieux

unread,
May 25, 2010, 12:40:29 PM5/25/10
to
On May 25, 4:54 pm, hresquiveloa <hresquive...@gmail.com> wrote:
> Hi. Can anyone help me to understand why the script shown below will
> not work as expected?
>
> foreach line {CAPEMEND/FOR-UP.AT2 CAPEMEND/FOR000.AT2 CHICHI/CHY025-
> W.AT2} {
> exec bash -c "curl -Ohttp://peer.berkeley.edu/smcat/data/ath/$line"

>
> }
>
> The script goal is to download a set of files (accelerograms) from the
> PEER Strong Motion Database... Thank you!

The loop is broken because bash spits out to stderr, which is
interpreted as an error by Tcl.

The error message given is simply the stderr output from curl, which
is easily confused with its normal behavior...
To convince yourself of this interpretation, just type

puts $::errorInfo

after the trial.

To fix this, add 2>@ stderr to the bash -c invocation:

2>@ stderr

You'll get the same progress info on the console, but
(1) it will flow in real time
(2) it will not generate a Tcl error
(3) it will go through all 3 rounds of the loop :)

-Alex

Fandom

unread,
May 25, 2010, 1:02:20 PM5/25/10
to
If haven't it working yet you can try:

foreach line {CAPEMEND/FOR-UP.AT2 CAPEMEND/FOR000.AT2 CHICHI/CHY025-
W.AT2} {

if {[catch {exec curl -O http://peer.berkeley.edu/smcat/data/ath/$line}
error]} {
puts "Error: $error"
}

}

hresquiveloa

unread,
May 25, 2010, 1:36:18 PM5/25/10
to
Alex, thank you very much for your help. Your workaround works just as
you described!

hresquiveloa

unread,
May 25, 2010, 1:38:25 PM5/25/10
to
Andres, thank you very much for your help. Everything is working now.
Thanks for your time.

akshatneha

unread,
Mar 16, 2015, 10:00:05 PM3/16/15
to
Hi, I am trying to execute curl command on press of button but it gives all the output in application error pop up.
Please help.

sample code:
proc getPage { } {
exec curl -X GET http://ipaddress/path
}


Rich

unread,
Mar 16, 2015, 11:30:43 PM3/16/15
to
man curl:

--stderr <file>
Redirect all writes to stderr to the specified file instead. If
the file name is a plain '-', it is instead written to stdout.

Mike Griffiths

unread,
Mar 17, 2015, 6:05:00 PM3/17/15
to
Rather then [exec]ing curl on the command line, you might consider using the TclCurl package which exposes the curl API to the Tcl interpreter. (http://wiki.tcl.tk/2638)

Gerald W. Lester

unread,
Mar 17, 2015, 6:18:13 PM3/17/15
to
Or even just using the http package that ships with Tcl.


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Alexandre Ferrieux

unread,
Mar 17, 2015, 7:18:11 PM3/17/15
to
Since you unearthed a nearly 5-year-old thread, you might read it as well.
Hint: look for "2>@ stderr".

-Alex
0 new messages