0
>> set signal_name [get_fanout abc_signal]
{xyz_blah_blah}
>> echo $signal_name
@142
>> set signal_name [get_fanout abc_signal]
{xyz_blah_blah}
>> echo $signal_name
@144
>>

I tried other stuff like catch etc, and every where, it returns @number. My goal is to be able to print the actual value instead of the number - xyz_blah_blah.

I am new to tcl. Want to understand, if this is an array or a pointer to an array or something like that. When I try the exact same thing with a different command, which returns just a value, then it works. This is a new command which returns value in parenthesis.

Please help. Thanks.

Somu Atluri
  • 1
  • 1
  • 1
  • `>>` is not the standard tcl prompt; is this tcl embedded in some other app that you're using? Also, `echo` is not a standard tcl command, `puts` is what you would normally use. – evil otto Feb 15 '13 at 20:44
  • Sorry I forgot to add more information about the environment. Yes it is a tool prompt. There was more stuff, I just removed everything to minimal. `puts` is not printing anything on the prompt. So I tried `echo`. – Somu Atluri Feb 15 '13 at 23:00

1 Answers1

0

Every Tcl command produces a result value, which you capture and use by putting the call of the command in [square brackets] and putting the whole lot as part of an argument to another command. Thus, in:

set signal_name [get_fanout abc_signal]

the result of the call to get_fanout is used as the second argument to set. I suggest that you might also like to try doing this:

puts "-->[get_fanout abc_signal]<--"

It's just the same, except this time we're concatenating it with some other small string bits and printing the whole lot out. (In case you're wondering, the result of puts itself is always the empty string if there isn't an error, and set returns the contents of the variable.)

If that is still printing the wrong value (as well as the right one beforehand, without arrow marks around it) the real issue may well be that get_fanout is not doing what you expect. While it is possible to capture the standard output of a command, doing so is a considerably more advanced technique; it is probably better to consider whether there is an alternate mechanism to achieve what you want. (The get_fanout command is not a standard part of the Tcl language library or any very common add-on library like Tk or the Tcllib collection, so we can only guess at its behavior.)

Community
  • 1
  • 1
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • Thanks for the reply Donal. I wanted to add more info on the environment. This is a tool prompt, which can run TCL scripts. I removed everything and pasted the bare minimum code. I tried the `puts`, just as you suggested. It did not print anything. `puts "-->[get_fanout abc_signal]<--"` So, just to try out if `puts` prints anything in my terminal. I tried this `set var 123` `puts "$var"` The puts did not return/print anything on the prompt. Is there any equivalent commands to `puts`. I will look into the other option you mentioned - capturing the standard output of a command. Thanks again – Somu Atluri Feb 15 '13 at 23:05
  • Something for messed up, so I restarted the tool, and tried `puts` again. And here is the result: `>>puts "-->[get_fanout abc_signal]<--" >>-->@16<--` It looks like, the command is returning some kind of pointer to an array. – Somu Atluri Feb 16 '13 at 00:17
  • Sorry, I dont know how to preserve the return characters in the comments. Anyways, I tried one of the solution from the link you pointed. Here is what I am doing in a sequence `set tint [interp create]` then `interp transfer {} stdout $tint` and when I try to write something say `puts "xyz"` it is giving me an error - `Error: Can not find channel named "stdout"`. Can you help me how to fix this. Am I missing something.. Thanks in advance, – Somu Atluri Feb 16 '13 at 00:17
  • Exactly that is the point of hiding the stdout. - to prevent that something is written to stdout. – Johannes Kuhn Feb 16 '13 at 11:29
  • Ok, understood the point. But how can I access what was just prevented from stdout? I did try to bring stdout back, and tried `puts $tint`, which I think will have the data that was supposed to go to stdout. But it didn't display anything.. – Somu Atluri Feb 17 '13 at 05:22
  • BTW, @JohannesKuhn, I am trying to use your solution from the other post. http://stackoverflow.com/questions/14530354/stdout-redirection – Somu Atluri Feb 17 '13 at 05:23
  • I know. Replacing std* channels is tricky, other solutions include Tclx's `dup stdout`, `close stdout`, channel creation (if stdout has been closed, the next channel that is created gets the name stdout). Or overriding `puts`. Note that an other interp still can have a stdout, in which case closing stdout and reopening it don't give you a channel called stdout. Just an other question: what is the output of the following snipiet: `set signal_name 1234; set signal_name` – Johannes Kuhn Feb 17 '13 at 15:05