Closed tidely closed 4 years ago
Just refactored it a little if you want to paste in this code.
def python_interpreter():
send(str.encode("python"))
recv(intBuff)
while True:
strCommand = input("\n" + ">>> ")
if strCommand.strip() == "":
continue
if strCommand == "exit" or strCommand == "exit()":
break
send(strCommand.encode())
strReceived = recv(intBuff).decode("utf-8").rstrip("\n")
if strReceived != "":
print(strReceived)
send(str.encode("exit"))
recv(intBuff)
def python_interpreter():
send(str.encode("received"))
while True:
strCommand = recv(intBuff).decode("utf-8")
if strCommand == "exit":
send(str.encode("exiting"))
break
old_stdout = sys.stdout
redirected_output = sys.stdout = StringIO()
try:
exec(strCommand)
print("")
strError = None
except Exception as e:
strError = f"{e.__class__.__name__}: "
try:
strError += f"{e.args[0]}"
except:
pass
finally:
sys.stdout = old_stdout
if strError:
send(strError.encode())
else:
send(redirected_output.getvalue().encode())
I will, one second
added remote python interpreter