From 212d47b93f2a432442ad7a5af97e329b7a27a4fe Mon Sep 17 00:00:00 2001 From: weilinfox Date: Sat, 7 Mar 2020 18:45:44 +0800 Subject: [PATCH] fix bc bug --- worker/bc.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/worker/bc.py b/worker/bc.py index 705dd4e..f20b9ab 100644 --- a/worker/bc.py +++ b/worker/bc.py @@ -365,13 +365,10 @@ def funMain (ch): def sysbc (arg): try: - arg = "echo \"" + arg + "\" | bc" - ret = subprocess.run(arg, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, check = True, timeout = 2) - retmes = str(ret.stdout) - retmes = retmes[2:len(retmes)-3] - retmes = retmes.replace('\\n', ". ") - retmes = retmes.replace('\\', "") - return retmes + arg = arg.replace("\'", "") + arg = "echo \'\'\'" + arg + "\'\'\' | bc" + ret = subprocess.run(arg, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, check = True, timeout = 1) + return bytes.decode(ret.stdout).replace("\n", "") except subprocess.TimeoutExpired: return "你干了啥怎么半天算不完啦!服务器爆了打你哦~" except: