diff options
author | Maurizio Lombardi <mlombard@redhat.com> | 2020-04-03 11:50:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 11:50:18 +0200 |
commit | 18ce78b530f01807b2f061e821b9329357bc5e02 (patch) | |
tree | d2ccc760469fb2c44c1811d641a0106d76a37f82 | |
parent | 1e5d2dda904a50c236a03c420db251d94a67e5da (diff) | |
parent | 0157f74a31adc1bd999ea5e5bc3a9c34af90b98c (diff) | |
download | targetcli-18ce78b530f01807b2f061e821b9329357bc5e02.tar.gz |
Merge pull request #166 from pkalever/Fix-BytesIO-StringIO
Fix StringIO/BytesIO stuck issue
-rwxr-xr-x | daemon/targetclid | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/daemon/targetclid b/daemon/targetclid index d4c6562..5df6ca2 100755 --- a/daemon/targetclid +++ b/daemon/targetclid @@ -32,9 +32,13 @@ import struct import fcntl import signal import errno -import io +if sys.version_info < (3, 0): + from io import BytesIO as StringIO +else: + from io import StringIO + err = sys.stderr class TargetCLI: @@ -154,24 +158,23 @@ class TargetCLI: connection.close() still_listen = False else: - self.con._stdout = self.con._stderr = f = io.BytesIO() + self.con._stdout = self.con._stderr = f = StringIO() try: # extract multiple commands delimited with '%' list_data = data.decode().split('%') for cmd in list_data: self.shell.run_cmdline(cmd) except Exception as e: - print(str(e), file=f) # push error to stream + print(str(e).encode(), file=f) # push error to stream # Restore self.con._stdout = self.con_stdout_ self.con._stderr = self.con_stderr_ - - output = f.getvalue() + output = f.getvalue().encode() var = struct.pack('i', len(output)) connection.sendall(var) # length of string if len(output): - connection.sendall(output.encode()) # actual string + connection.sendall(output) # actual string f.close() |