diff options
author | Maurizio Lombardi <mlombard@redhat.com> | 2020-01-27 09:54:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-27 09:54:14 +0100 |
commit | 23877ab4afbf0c2fe4092936261d92d7b7fbff11 (patch) | |
tree | 32252c59ba1c7250a3f84776a78ca891dace705b | |
parent | 94d971dd1d50d6189ce64b64b8f9fccc965a3312 (diff) | |
parent | 3db75315b7e436e57943efb132f7b331a7a7744c (diff) | |
download | targetcli-23877ab4afbf0c2fe4092936261d92d7b7fbff11.tar.gz |
Merge pull request #156 from iammattcoleman/replace-file-with-stringio
Use StringIO as a buffer instead of a file
-rwxr-xr-x | daemon/targetclid | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/daemon/targetclid b/daemon/targetclid index fb472dc..dfc22ce 100755 --- a/daemon/targetclid +++ b/daemon/targetclid @@ -32,6 +32,7 @@ import struct import fcntl import signal import errno +import io err = sys.stderr @@ -153,7 +154,7 @@ class TargetCLI: connection.close() still_listen = False else: - self.con._stdout = self.con._stderr = f = open("/tmp/data.txt", "w") + self.con._stdout = self.con._stderr = f = io.StringIO() try: # extract multiple commands delimited with '%' list_data = data.decode().split('%') @@ -165,14 +166,14 @@ class TargetCLI: # Restore self.con._stdout = self.con_stdout_ self.con._stderr = self.con_stderr_ - f.close() - with open('/tmp/data.txt', 'r') as f: - output = f.read() - var = struct.pack('i', len(output)) - connection.sendall(var) # length of string - if len(output): - connection.sendall(output.encode()) # actual string + output = f.getvalue() + var = struct.pack('i', len(output)) + connection.sendall(var) # length of string + if len(output): + connection.sendall(output.encode()) # actual string + + f.close() def usage(): |