Introduction
I recently started working on a legacy product, under Linux, which incorporates a builtin TCL shell. Due to company limitations, I can't gain control to "behind the scenes" and all of the code I can write must be run under this TCL shell, handling the pre-defined clumsy TCL API of the product.
I found myself wondering a few times whether it will be possible to patch some Python into this setup, as some solutions seem more legitimate in Python than in TCL. By patching Python I mean: either calling the Python code from the TCL code itself (which can be done with Elmer, for example), or to use Python from outside of the product to wrap the TCL API (for which I found no "classic" solution).
The Problem
Given that the product already has an existing TCL shell in it, most solutions I browsed through (e.g. Tkinter) can't be used to run the TCL code from Python. I need to "inject" the code to the existing shell.
Solutions Considered
As a solution, I thought about bringing up a simple server on the TCL side which runs simple commands it receives from the Python side. I wrote a small demo and it worked. This enabled me to write a nice, class based, wrapper in Python for the clumsy TCL API, also manage a command queue, etc.
Another two solutions I thought of is forking the software from Python and playing with the read/write file descriptors or connecting through FIFO rather than a socket.
However, I wondered whether I'm actually doing it right or can you suggest a better solution?
Thanks in advance.
quickdraw.pyis a code example where Python function calls are automatically translated into quickdraw commands and piped into the corresponding java process. The point is that the rest of the Python code doesn't need to be aware that there is a java subprocess invovled. Sockets are more powerful and more portable than pipes (sockets may work withselect()even on Windows) though pipes might be simpler in some cases.tkinter.Tcl()interpreter with the Tcl shell and send commands via TCP/IP. Afterwards just wrap the tkinter wrapper in your Python code and be done. (see core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/… and if you want, the wire protocol is documented too)