I would like to open a bash session in python and keep interacting with it as if it was a terminal. This is what I have so far:
import subprocess as s
class Session:
proc = None
def execute(self, cmd):
if self.proc is None:
self.proc = s.Popen("/bin/bash", shell=True, stdin=s.PIPE, stdout=s.PIPE, stderr=s.STDOUT)
cmd = cmd + ' ; echo EOF\n'
self.proc.stdin.write(cmd.encode())
output = ''
while not output.endswith("EOF"):
output += self.proc.stdout.read(1).decode()
return output
sess = Session()
sess.execute("export MY_VAR=HELLO")
sess.execute("git clone https://github.com/internetsadboy/crapi.git")
However, during git clone I get this output, and it fails
Cloning into 'crapi'...
EOF