🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.tcl
Article #54

Re: Python

#54
From: Christian Gollwitzer
Date: Thu, 15 Oct 2026 08:37
48 lines
2572 bytes
Am 14.10.26 um 15:07 schrieb saito:
> 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?

Maybe it's failing because python uses GNU readline and expects a real 
terminal, and behaves differently when you redirect stdin to a pipe.

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.

Python code is like  this:

     def slave_loop(self):
         tkroot.createfilehandler(sys.stdin, tkinter.READABLE, 
self.stdin_handler)

     def stdin_handler(self, file, mask):
         cmd = file.readline()

         if not cmd:
             exit()
         try:
             print(eval(cmd))
         except:
             print('ERROR')
             traceback.print_exc()

         self.slave_loop()



The Python program in this case is itself a Tkinter app, but it should 
work similarly well without an event loop like this

while True:
     cmd=sys.stdin.readline()
     eval(cmd)

Obviously needs some error handling etc.

Christian
Technical Details
Message-ID: <11aq3bq$27p1e$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11anurd$1gcvi$2@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Christian Gollwitzer <auriocus@gmx.de>
Newsgroups: comp.lang.tcl
Subject: Re: Python
Date: Thu, 15 Oct 2026 10:37:13 +0200
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <11aq3bq$27p1e$1@dont-email.me>
References: <11anurd$1gcvi$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 15 Oct 2026 08:37:15 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2352174"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+ACXrkrjzeEgs4hXSGGH9Jo6qvJmxWmBc="; posting-host="a25d17912626d5b2383f3e95d1e0a347"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GBPHKKeBOTq570FGBa1zpDhruQs= sha256:JprZzcxIA/So1g3pBIQTytuSLs9VxTEyjK+iXG2734Q=
	sha1:M7E/5W8ll0Vw8/0jMsyvIjix7QE= sha256:iwduGC4FsXlrqBQWGqs1e3DX17FWUg35MmHO0vsU+Gs=
In-Reply-To: <11anurd$1gcvi$2@dont-email.me>