![](/static/61a827a1/assets/icons/icon-96x96.png)
![](https://lemmy.world/pictrs/image/4271bdc6-5114-4749-a5a9-afbc82a99c78.png)
that is a little more complicated
p.communicate()
will take a string (or bytes) and send it to the stdin of the process, then wait for p
to finish execution
there are ways to stream input into a running process (without waiting for the process to finish), but I don’t remember how off the top of my head
from shutil import which
from subprocess import Popen, PIPE, run
from pathlib import Path
LS = which('ls')
REV = which('rev')
ls = run([LS, Path.home()], stdout=PIPE)
p = Popen([REV], stdin=PIPE, stdout=PIPE)
stdout, stderr = p.communicate(ls.stdout)
print(stdout.decode('utf-8'))
I’ve been running Linux for 4 years, but this still hurts to read