0
int main() {
    Tcl_Interp *interp = Tcl_CreateInterp(); 

    Tcl_Eval(interp, "close stdout");
    Tcl_Eval(interp, "puts hello");

    std::cout << "other output" << std::endl;
}

I have a program which uses Tcl_Interpreter. I don't want to see its output in stdout, so I am closing it. But it closes stdout of whole program and "other output" is not displayed too. My program could have lots of other outputs. Why Tcl interpreter disables it.

This kind of situation is when I am trying to evaluate exit command in interpreter. I expect that it should only destroy, delete or disable the interpreter, but it is calling std::exit which closes whole program, which retains undestructed objects.

I know that there may be workarounds to this situations but I am curios why does Tcl Interpreter implemented in such way. It would be more useful that it changes only itself, not the whole program.

Ashot
  • 10,807
  • 14
  • 66
  • 117
  • Tcl was designed to be the scripting language glue for programs — that was its original design brief — and one of those things that code might want to do is `exit`. If you don't want `exit` to behave like that, delete or replace that command; Tcl's built-in `exit` is really just part of a “standard library” (like all the other commands) and isn't really all that special. – Donal Fellows May 04 '13 at 12:00

2 Answers2

1

You might be better off redirecting the TCL output somewhere else rather than closing stdout:

Community
  • 1
  • 1
Gui13
  • 12,993
  • 17
  • 57
  • 104
0

If you want an independent Tcl subprocess, you should start it with system("tcl YourScript.tcl"). When the interpreter runs in your process, it acts as part of your process.

MSalters
  • 173,980
  • 10
  • 155
  • 350