From 3db75315b7e436e57943efb132f7b331a7a7744c Mon Sep 17 00:00:00 2001 From: Matt Coleman Date: Thu, 7 Nov 2019 18:21:32 -0500 Subject: [PATCH] Use StringIO as a buffer instead of a file --- daemon/targetclid | 17 +++++++++-------- 1 file 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(): -- 2.21.0