API Tcl C: redireciona o stdout do interp Tcl incorporado para um arquivo sem afetar todo o programa
#include <tcl.h>
int main(int argc, char** argv)
{
Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_Channel stdoutChannel = Tcl_GetChannel(interp, "stdout", NULL);
Tcl_UnregisterChannel(interp, stdoutChannel);
Tcl_Channel myChannel = Tcl_OpenFileChannel(interp, "/home/aminasya/nlb_rundir/imfile", "w", 0744);
Tcl_RegisterChannel(interp, myChannel);
Tcl_Eval(interp, "puts hello");
}
Neste código, tentei fechar o canal stdout e redirecioná-lo para o arquivo. (Como descritoObter a saída do Tcl C Procedures). Após a execução, "imfile" é criado, mas vazio. O que estou fazendo errado?
Eu tenho vistoComo posso redirecionar o stdout para um arquivo no tcl também, mas eu preciso fazer isso usando a API Tcl C.
Eu também tentei desta forma, mas novamente sem resultado.
FILE *myfile = fopen("myfile", "W+");
Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_Channel myChannel = Tcl_MakeFileChannel(myfile, TCL_WRITABLE);
Tcl_SetStdChannel(myChannel, TCL_STDOUT);