Home > Archive > Tcl > January 2006 > Yet Another Flavor of stdio redirection problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Yet Another Flavor of stdio redirection problem
|
|
|
| Hi All,
I am developing an application which is running a Python front-end from
a dedicated command input/output window. This application is also
linked with a submodule which has a Tcl front-end. Most of the time,
the application does not need to pilot the module through its Tcl front
end: it uses direct C++ APIs to communicate with the main application.
However I have python hooks available to send individual Tcl commands
to the submodule's Tcl interpreter when I need to pilot the submodule
using predefined Tcl commands. And I also have a Python hook to invoke
the Tcl interpreter to pilot my submodule in interactive mode in case
the user wanted to have more direct access into the submodule's command
set. Try as I might, I could not find a way to make the Tcl
interpreter's IOs to be attached to the same command window that is
used by my application's Python front-end: it insists on using the
stdio attached to the process, which is usually attached to the tty
from which my application was launched (for instance an xterm shell
window).
There are two difficulties there:
1) I have been peering at the Tcl source code in tclUnixChan.c,
TclIO.c, etc... and could not locate the place where the code figures
out which handles to use for creating the stdin, stdout and stderr
channels when initializing itself. I suppose it is getting this
information by looking up the I/O devices attached to the application's
process, but where is that bloody code? I need this information to know
what kind of handle is needed and how I can pass a handle of the same
type describing the I/O device attached to my Python command window.
2) Once I have identified which handle to use, how can I access the I/O
device handle attached to my Python command window?
As an alternative, I suppose I could live with some code that would
bring up a dedicated window to run the interactive Tcl front-end of the
submodule. I have seen similar code for doing this for stdout and
stderr on the internet (e.g.
http://cvs.sf.net/viewcvs.py/tomaso...=HEAD&view=auto
or http://www.openmash.org/lxr/source/...nsole.c?c=tk8.3), but
it does not seem to handle stdin.
Any help would be greatly appreciated.
Regards,
LMN.
| |
| Don Porter 2006-01-25, 7:15 pm |
| lmn wrote:
> .... Try as I might, I could not find a way to make the Tcl
> interpreter's IOs to be attached to the same command window that is
> used by my application's Python front-end: it insists on using the
> stdio attached to the process, ...
Did any of your trials involve calls to Tcl_SetStdChannel() ?
--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|_______________________________________
_______________________________|
| |
|
| Yes, I looked at Tcl_SetStdChannel to do what I need to do. It takes
two parameters, of which the first is of type Tcl_channel (I think I
know what the second parameter, should be passed as):). So maybe my
question boils down to how do I create a Tcl_channel handle
corresponding to my Python command window's tty?
LMN.
| |
| Don Porter 2006-01-25, 7:15 pm |
| lmn wrote:
> Yes, I looked at Tcl_SetStdChannel to do what I need to do. It takes
> two parameters, of which the first is of type Tcl_channel (I think I
> know what the second parameter, should be passed as):). So maybe my
> question boils down to how do I create a Tcl_channel handle
> corresponding to my Python command window's tty?
Give Tcl_MakeFileChannel() a try.
--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|_______________________________________
_______________________________|
| |
|
| Thanks. What is the 'handle' parameter supposed to be? The result of a
call to fopen? Should I use freopen to get a FILE * handle to the
filename attached to the Python InteractiveInterpreter object
underlying my Python command window?
| |
| Donal K. Fellows 2006-01-26, 7:59 am |
| lmn wrote:
> Thanks. What is the 'handle' parameter supposed to be? The result of a
> call to fopen? Should I use freopen to get a FILE * handle to the
> filename attached to the Python InteractiveInterpreter object
> underlying my Python command window?
On Unix, it's a file descriptor. (You can get it from a FILE* by using
the fileno(3) function.) On Windows, I think it is a HANDLE of some kind.
Donal.
|
|
|
|
|