[Python-ideas] Running Python commands from a Shell

Steven D'Aprano steve at pearwood.info
Fri Feb 1 21:44:25 EST 2019


On Fri, Feb 01, 2019 at 07:21:47PM -0600, eryk sun wrote:

> bash coproc runs a process in the background with stdin and stdout
> redirected to pipes. The file descriptors for our end of the pipes are
> available in an array with the given name (e.g. P3). The default array
> name is COPROC.

Thanks for the explanation.

> As soon as  "pipe" is mentioned, anyone familiar with the REPL's
> behavior with pipes should know that making this work will require the
> -i command-line option to force interactive mode. Otherwise stdout
> will be fully buffered. For example:
[...]


I wonder... could Python automatically detect when it is connected to 
pipes and switch buffering off?


> > And are we supposed to know what ">&${P3[1]}" does? It looks like your
> > cat walked over your keyboard.
> 
> It redirects the command's standard output (>) to the file descriptor
> (&) in index 1 of the P3 array (${P3[1]}), which is our end of the
> pipe that's connected to stdin of the co-process.

And this is why I don't program in bash :-)



-- 
Steven


More information about the Python-ideas mailing list