For Programmers: Free Programming Magazines  


Home > Archive > Tcl > December 2006 > Tcl command to evaluate a tcl script?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Tcl command to evaluate a tcl script?
prabu

2006-12-18, 4:16 am

Hi all,

I need to evaluate a separate tcl file within a tcl file. Is there any
tcl command to evaluate a tcl file ?

Regards,
Prabu.K

Darren New

2006-12-18, 4:16 am

prabu wrote:
> I need to evaluate a separate tcl file within a tcl file. Is there any
> tcl command to evaluate a tcl file ?


You're probably looking for the "source" command.

Other commands of interest would be "package require" or "eval". The
command "load" is for binary shared libraries.

--
Darren New / San Diego, CA, USA (PST)
Scruffitarianism - Where T-shirt, jeans,
and a three-day beard are "Sunday Best."
prabu

2006-12-18, 4:16 am

Thanks Darren. But what my need is that I am writing a tcl script which
is going to take any tcl script as input and should return the output
of the file. How can I do that?

Regards,
Prabu

Darren New wrote:
> prabu wrote:
>
> You're probably looking for the "source" command.
>
> Other commands of interest would be "package require" or "eval". The
> command "load" is for binary shared libraries.
>
> --
> Darren New / San Diego, CA, USA (PST)
> Scruffitarianism - Where T-shirt, jeans,
> and a three-day beard are "Sunday Best."


Fredderic

2006-12-18, 4:16 am

On 17 Dec 2006 21:16:16 -0800,
"prabu" <catchme.prabu@gmail.com> wrote:

> Thanks Darren. But what my need is that I am writing a tcl script
> which is going to take any tcl script as input and should return the
> output of the file. How can I do that?


[eval] ?


Fredderic
Darren New

2006-12-18, 4:16 am

prabu wrote:
> Thanks Darren. But what my need is that I am writing a tcl script which
> is going to take any tcl script as input


It takes any tcl script as input? Or it takes the name of any file
containing tcl script as input? That's two different requirements.
The first is [eval $variable_containing_script].
The second is [source $variable_containing_name_of_file].

You'll need to read the manual pages for these operations. If you don't
have them handy, google for "tcl man source" or "tcl man eval".

> and should return the output of the file.


Files don't "output". Scripts output.

That said, do you mean the return value from evaluating the script, or
do you mean what the script printed, such as with [puts]? If you mean
what it printed, do you want to know what it printed to stdout, stderr,
both?

If you mean the return value, that would be the result of calling
[eval], which passes the return value of the script as its own return value.

If you mean what was printed to stdout, that's a bit harder, but not a
whole lot. You basically rename the [puts] command to accumulate output
in a variable before you call [source].

--
Darren New / San Diego, CA, USA (PST)
Scruffitarianism - Where T-shirt, jeans,
and a three-day beard are "Sunday Best."
prabu

2006-12-18, 4:16 am

Thanks. It was helpful.
Prabu

Darren New wrote:
> prabu wrote:
>
> It takes any tcl script as input? Or it takes the name of any file
> containing tcl script as input? That's two different requirements.
> The first is [eval $variable_containing_script].
> The second is [source $variable_containing_name_of_file].
>
> You'll need to read the manual pages for these operations. If you don't
> have them handy, google for "tcl man source" or "tcl man eval".
>
>
> Files don't "output". Scripts output.
>
> That said, do you mean the return value from evaluating the script, or
> do you mean what the script printed, such as with [puts]? If you mean
> what it printed, do you want to know what it printed to stdout, stderr,
> both?
>
> If you mean the return value, that would be the result of calling
> [eval], which passes the return value of the script as its own return value.
>
> If you mean what was printed to stdout, that's a bit harder, but not a
> whole lot. You basically rename the [puts] command to accumulate output
> in a variable before you call [source].
>
> --
> Darren New / San Diego, CA, USA (PST)
> Scruffitarianism - Where T-shirt, jeans,
> and a three-day beard are "Sunday Best."


Glenn Jackman

2006-12-18, 8:09 am

At 2006-12-18 12:16AM, "prabu" wrote:
> Thanks Darren. But what my need is that I am writing a tcl script which
> is going to take any tcl script as input and should return the output
> of the file. How can I do that?


Really?
file delete -force ~

I suggest you read about safe interpreters. http://wiki.tcl.tk/1496

--
Glenn Jackman
Ulterior Designer
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com