[Python-ideas] Running Python commands from a Shell (was: Option of running shell/console commands inside the REPL)

Dan Sommers 2QdxY4RzWzUUiLuE at potatochowder.com
Fri Feb 1 15:38:43 EST 2019

On 2/1/19 2:26 AM, João Matos wrote:
> Hello,
> Consider adding the option of running shell/console commands inside the REPL.
> Something like

I first ran into this in the days of teletypes and dumb
terminals, where other programs let you run shell commands
from inside them.  Now the shoe appears to be on the other

So why not turn that around?  ksh (since way back when) and
bash (since 2008, according to what I read somewhere online)
have "co-processes," which allow you to run a command "in
the background," and send commands and receive replies from
it.  So I tried it with Python, but it didn't work:

     $ coproc P3 { python3; }
     $ echo 'import sys; print(sys.version)' >&${P3[1]}
     $ read v <&${P3[0]}
     [the read command just waits forever]

A pile of experiments and examples from web pages later, I
think it's Python and not me.  My example, with suitable
changes to the literal in the echo command, works with sbcl
and erl, but not python3.  If I start python3 as follows:

     $ coproc P3 { python3 | tee /tmp/P3; }

then I can see the empty /tmp/P3 file, and the python3 and
tee processes, but /tmp/P3 remains empty.

Any ideas as to why not?


More information about the Python-ideas mailing list