Update SW_run.py
Browse files
SW_run.py
CHANGED
@@ -8,11 +8,6 @@ log_file = '/bushu/logs_run.txt'
|
|
8 |
if os.path.exists(log_file):
|
9 |
os.remove(log_file)
|
10 |
|
11 |
-
# 检查是否存在 url.txt 文件,如果存在则删除它
|
12 |
-
url_file = '/bushu/url.txt'
|
13 |
-
if os.path.exists(url_file):
|
14 |
-
os.remove(url_file)
|
15 |
-
|
16 |
# 配置日志
|
17 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
18 |
|
@@ -27,24 +22,10 @@ logging.getLogger().addHandler(console_handler)
|
|
27 |
sys.stdout = logging.getLogger().handlers[0].stream
|
28 |
sys.stderr = logging.getLogger().handlers[0].stream
|
29 |
|
30 |
-
# 切换到/bushu/ui目录
|
31 |
-
subprocess.run(["cd", "/bushu/ui"], shell=True)
|
32 |
-
|
33 |
try:
|
34 |
-
# 在
|
35 |
with open(log_file, 'a') as log_file_handle:
|
36 |
-
|
37 |
-
for line in iter(process.stdout.readline, ''):
|
38 |
-
if "Running on" in line:
|
39 |
-
# 如果日志行包含 "Running on",将它写入 url.txt 文件
|
40 |
-
with open(url_file, 'a') as url_file_handle:
|
41 |
-
url_file_handle.write(line)
|
42 |
-
else:
|
43 |
-
# 否则,将日志行写入 logs_run.txt 文件
|
44 |
-
log_file_handle.write(line)
|
45 |
-
log_file_handle.flush()
|
46 |
-
process.stdout.close()
|
47 |
-
process.wait()
|
48 |
except subprocess.CalledProcessError as e:
|
49 |
# 捕获异常并记录到日志文件
|
50 |
logging.exception(f"程序发生异常: {e}")
|
@@ -54,4 +35,4 @@ except Exception as e:
|
|
54 |
finally:
|
55 |
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
56 |
logging.getLogger().removeHandler(console_handler)
|
57 |
-
console_handler.close()
|
|
|
8 |
if os.path.exists(log_file):
|
9 |
os.remove(log_file)
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
# 配置日志
|
12 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
|
|
22 |
sys.stdout = logging.getLogger().handlers[0].stream
|
23 |
sys.stderr = logging.getLogger().handlers[0].stream
|
24 |
|
|
|
|
|
|
|
25 |
try:
|
26 |
+
# 在try块中运行/bushu/ui/launch.py,并将输出重定向到日志文件
|
27 |
with open(log_file, 'a') as log_file_handle:
|
28 |
+
subprocess.run(['python', '/bushu/ui/launch.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
except subprocess.CalledProcessError as e:
|
30 |
# 捕获异常并记录到日志文件
|
31 |
logging.exception(f"程序发生异常: {e}")
|
|
|
35 |
finally:
|
36 |
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
37 |
logging.getLogger().removeHandler(console_handler)
|
38 |
+
console_handler.close()
|