Get the output from Tcl C Procedures

前端 未结 1 1606
Happy的楠姐
Happy的楠姐 2021-01-14 21:45

I have a C shell that usually calls Tcl routines using Tcl_Eval. Normally I was fine with just executing what the user typed and getting some status as a result. However, no

相关标签:
1条回答
  • 2021-01-14 22:00

    I think you could go like this:

    1. Create a pipe by calling pipe(2).
    2. Then in your interp:

      1. Close stdout by calling Tcl_Close() on it.
      2. Turn the write-end file descriptor of your pipe into Tcl's stdout channel by calling Tcl_MakeChannel() right after closing stdout.

      Or use just replace the stdout with a call to Tcl_SetStdChannel().

    3. Process the data coming from the pipe.

    As to your side note — I think you could just call Tcl_Eval() in your interpreter and process the returned list using the list-processing functions from the Tcl API.

    Update (from one of my comments): after some more thought I think it might be possible to just create a custom Tcl channel which implementation would just save away the data written to it and then register an instance of such a channel as stdout. See Tcl_CreateChannel() and Tcl_RegisterChannel().

    0 讨论(0)
提交回复
热议问题