From 003732cd322cfd4d66d8494ee8db58d0772144a5 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 21 Feb 2025 09:25:16 +0800 Subject: [PATCH] fix: read exe return result with output to file --- tests/army/frame/eos.py | 44 +++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/army/frame/eos.py b/tests/army/frame/eos.py index 802b62e052..363714a6d1 100644 --- a/tests/army/frame/eos.py +++ b/tests/army/frame/eos.py @@ -64,12 +64,23 @@ def exeNoWait(file): return exe(cmd) # run return output and error -def run(command, timeout = 10): - process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - process.wait(timeout) +def run(command, show=True): + # out to file + id = time.clock_gettime_ns(time.CLOCK_REALTIME) % 100000 + out = f"out_{id}.txt" + err = f"err_{id}.txt" + + ret = exe(command + f" 1>{out} 2>{err}") - output = process.stdout.read().decode(encoding="gbk") - error = process.stderr.read().decode(encoding="gbk") + # read from file + output = readFileContext(out) + error = readFileContext(err) + + # del + if os.path.exists(out): + os.remove(out) + if os.path.exists(err): + os.remove(err) return output, error @@ -84,4 +95,25 @@ def runRetList(command, timeout=10): # def delFile(file): - return exe(f"rm -rf {file}") \ No newline at end of file + return exe(f"rm -rf {file}") + +def readFileContext(filename): + file = open(filename) + context = file.read() + file.close() + return context + +def writeFileContext(filename, context): + file = open(filename, "w") + file.write(context) + file.close() + +def appendFileContext(filename, context): + global resultContext + resultContext += context + try: + file = open(filename, "a") + wsize = file.write(context) + file.close() + except: + print(f"appand file error context={context} .") \ No newline at end of file