[Python-ideas] Running Python commands from a Shell

Steven D'Aprano steve at pearwood.info
Fri Feb 1 17:46:23 EST 2019


On Fri, Feb 01, 2019 at 04:28:25PM -0600, Dan Sommers wrote:
> On 2/1/19 3:48 PM, Steven D'Aprano wrote:
> > On Fri, Feb 01, 2019 at 02:38:43PM -0600, Dan Sommers wrote:
> >
> >> 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]
> >
> > This is another good example of the problem James was referring to in
> > the thread about clearer communication. Don't assume we all know what
> > coproc does.
> 
> As I indicated in what you quoted, shell co-processes allow you to run a
> command in the background and interact with that command from your
> shell.

Okay, but what does that mean in practice? What does it require to make 
it work with Python? What is your expected input and output?

This is a Python forum. You can assume your readers have a good level of 
knowledge about Python. Outside of that, you can expect to lose a 
significant portion of your audience if you start talking about 
features, practices etc that aren't supported by the Python language, 
stdlib and perhaps a few of the better-known third-party libraries.

E.g. me, I have no idea what you mean by "interact with that command 
from your shell". If you're a sys admin, you might do that fifty times a 
day for all I know, but I've never knowingly done it.

And are we supposed to know what ">&${P3[1]}" does? It looks like your 
cat walked over your keyboard.


-- 
Steve


More information about the Python-ideas mailing list