Код: Выделить всё
from subprocess import Popen, PIPE, STDOUT
p = Popen(['bc', '-q', '-i'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
while True:
if p.poll() is None:
data = input("> ")
data = data + "\n"
out, err = p.communicate(data.encode())
print(out.decode().rstrip())
else:
break
выход:
python mathserver. пи
Код: Выделить всё
> 1+2
1+2
3
Подробнее здесь: https://stackoverflow.com/questions/782 ... -in-python