Having a simple subprocess example.
import subprocess
sshProcess = subprocess.Popen(['ssh','localhost','/usr/local/bin/fish'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
errors='ignore',
bufsize=0)
sshProcess.stdin.write("echo 124\n")
sshProcess.stdin.close()
print(sshProcess.stdout.read(end=""))
The same but with stdin.close() after stdout.read() will block for ever.
print(sshProcess.stdout.read(end=""))
sshProcess.stdin.close()
I would like to read() data till it is available and do not block.
Similar question Non-blocking read on a subprocess.PIPE in python has very complicated answers. Does Python have such a simple mechanisms as POSIX to check how much data available in fd?
POSIX C
int bytes_available;
ioctl(fd, FIONREAD, &bytes_available);