I am trying to send arguments to a subprocess' stdin. In my case, it is an image downloaded with Requsts.
Here is my code:
from subprocess import Popen, PIPE, STDOUT
img = requests.get(url, stream=True)
i = img.raw.read()
proc = subprocess.Popen(['icat', '-'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
proc.communicate(i)
#proc.stdin.write(i) # I tried this too
Unfortunately, the subprocess does nothing, and I get no errors. What is wrong with my code, and is there a cross-platform solution?
icat
queries your terminal to see what dimensions to resize the image to, but a pipe is not suitable as a terminal and you end up with empty output. The help information fromicat
states:When you use the
-k
switch output is produced.There is no need to stream here, you can just leave the loading to
requests
and pass in the response body, un-decoded:The
stderr
value will be empty, butstdout
should contain transformed image data (ANSI colour escapes):