Tcl C API: redirect stdout of embedded Tcl interp to a file without affecting the whole program

前端 未结 3 404
终归单人心
终归单人心 2021-01-26 00:07
#include 
int main(int argc, char** argv)
{
    Tcl_Interp *interp = Tcl_CreateInterp();

    Tcl_Channel stdoutChannel = Tcl_GetChannel(interp, \"stdout\",         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 00:37

    Try this:

    FILE *myfile = fopen("myfile", "W+");
    Tcl_Interp *interp = Tcl_CreateInterp(); 
    Tcl_Channel myChannel = Tcl_MakeFileChannel(myfile, TCL_WRITABLE);
    Tcl_RegisterChannel(myChannel);
    Tcl_SetStdChannel(myChannel, TCL_STDOUT);
    

    You need to register the channel with the interpreter before you can reset the std channel to use it.

提交回复
热议问题