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

sourcing tcl script with arguments

0 views
Skip to first unread message

Renaud

unread,
Apr 18, 2003, 9:43:16 AM4/18/03
to
Hello,

I'm trying to "source" a tcl script, but I need to provide arguments
to it.
When running the program from the tclsh, I can provide arguments but
if I want to run it from within another script, it does not work.
Can someone help me ?

Thanks

Renaud

Don Porter

unread,
Apr 18, 2003, 9:55:01 AM4/18/03
to
Renaud wrote:
> I'm trying to "source" a tcl script, but I need to provide arguments
> to it.
> When running the program from the tclsh, I can provide arguments but
> if I want to run it from within another script, it does not work.

set argv [list "the" "arguments" "you" "want"]
set argc [llength $argv]
source yourScript.tcl

--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Mark G. Saye

unread,
Apr 18, 2003, 10:28:40 AM4/18/03
to Renaud

I wrote this little proc a while ago in response to a similar question:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=3C1B906D.1121DA09%40yahoo.com&rnum=2&prev=/groups%3Fq%3Dsource%2Bauthor:Mark%2Bauthor:G.%2Bauthor:Saye%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D3C1B906D.1121DA09%2540yahoo.com%26rnum%3D2

Or in case that link doesn't work for you, a slightly modified version:

proc src {file args} {
set argc $::argc
set argv $::argv
set ::argc [llength $args]
set ::argv $args
uplevel [list source $file]
set ::argc $argc
set ::argv $argv
}

Then you can do:

% src yourfile.tcl arg1 arg2 arg3

--
Mark G. Saye
markgsaye @ yahoo.com

Renaud

unread,
Apr 19, 2003, 10:37:02 AM4/19/03
to
"Mark G. Saye" <mark...@yahoo.com> wrote in message news:<3EA00B98...@yahoo.com>...


Thanks a lot to everybody.

Renaud

0 new messages