I would like to start a python session, send it some simple commands and
get the results back. From Tcl, I have tried opening a pipe with RDWR
and r+ and various fconfigure/filevenets and none seem to work.
AI bot solutions end up hanging on the reading part as well.
Is this use case possible?
You should probably have a look at Tohil - this makes the interconnection between
Tcl and Python quite easy. See https://wiki.tcl-lang.org/page/Accessing+Tcl+and+Python+from+one+another
On 10/14/2026 9:13 AM, Arjen wrote:
You should probably have a look at Tohil - this makes the interconnection between
Tcl and Python quite easy. See https://wiki.tcl-lang.org/page/Accessing+Tcl+and+Python+from+one+another
I'd try it but it looks like it doesn't run on Windows yet. I would like
to avoid binary extensions if possible.
I am not sure how the file open modes RDWR and r+ are supposed to work. Perhaps my challenge is isolating the two ends of the pipe. I am pretty
sure I have seen this being done but I am not sure where to start looking.
On 10/14/2026 9:13 AM, Arjen wrote:
You should probably have a look at Tohil - this makes the interconnection between
Tcl and Python quite easy. See https://wiki.tcl-lang.org/page/Accessing+Tcl+and+Python+from+one+another
I'd try it but it looks like it doesn't run on Windows yet. I would like
to avoid binary extensions if possible.
I am not sure how the file open modes RDWR and r+ are supposed to work. Perhaps my challenge is isolating the two ends of the pipe. I am pretty
sure I have seen this being done but I am not sure where to start looking.
Perhaps some of the discussion here:
https://wiki.tcl-lang.org/page/chan+pipe
will be helpful?
I have used it on Windows (not extensively I admit),
but your method with pipes
should work as well. Have you checked the Wiki for examples? (I see Rich has made a similar remark)
On 10/14/2026 9:56 AM, Arjen wrote:
I have used it on Windows (not extensively I admit),
Interesting! I wonder if their info is simply out of date. Under their
"To Do", it says: "We'd like to have Tohil work on Windows if someone
would be willing to take it on."
but your method with pipes
should work as well. Have you checked the Wiki for examples? (I see Rich has
made a similar remark)
I hope so too. That was indeed the command that I was trying to find. Sometimes you just don't know what magic words to use.
Thank you!
If it does not work, can you show us via a simple/minimal example
how you are trying to do it?
Why not write a temp file with the simple commands and call python with
that?
set fd [file tempfile tmpfile]
puts $fd $simple_commands
close $fd
set result [exec python $tmpfile]
On 10/14/2026 10:30 AM, Arjen wrote:
If it does not work, can you show us via a simple/minimal example
how you are trying to do it?
I am getting back to it. I read thru the docs on [chan pipe]. It seems a powerful and flexible construct. Unfortunately no detailed explanation
or examples exist beyond redirecting or controlling the output part.
This has syntax errors:
=======================================
lassign [chan pipe] toPy fromPy
chan configure $toPy -buffering line
chan configure $fromPy -buffering line
set fileID [open "|python.exe <$toPy 2>@ $fromPy" r] =======================================
% couldn't read file "file52551d0": no such file or directory
where that handle is the value of "toPy"
I would like to start a python session, send it some simple commands and
get the results back. From Tcl, I have tried opening a pipe with RDWR
and r+ and various fconfigure/filevenets and none seem to work.
AI bot solutions end up hanging on the reading part as well.
Is this use case possible?
YOu could write a Python script that reads from stdin and executes the commands. I'm using a scheme like this in a larger Python application
that is remotely controlled from a Tcl GUI.
I have similar inter-process-pipes, though between two TCL processes.
For line-oriented communication, I simply base64-encode the whole
content and send one line, base64-decode on the other side.
That way each message (regardless how long within sane limits :-)
is one line only.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,142 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 93:09:42 |
| Calls: | 14,704 |
| Calls today: | 2 |
| Files: | 186,497 |
| D/L today: |
2,361 files (783M bytes) |
| Messages: | 2,551,657 |