diff options
author | Matt Coleman <matt@datto.com> | 2019-11-07 18:21:32 -0500 |
---|---|---|
committer | Matt Coleman <matt@datto.com> | 2019-11-07 19:15:27 -0500 |
commit | 3db75315b7e436e57943efb132f7b331a7a7744c (patch) | |
tree | bd129e1a37787ee581c35cb8f30b2191c3b5919a | |
parent | 06076aba7e9e9bd4a1e84bac61e85265e8075b8e (diff) | |
download | targetcli-3db75315b7e436e57943efb132f7b331a7a7744c.tar.gz |
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(): |