Update nologs.py
Browse files
nologs.py
CHANGED
@@ -3,9 +3,10 @@ import sys
|
|
3 |
import logging
|
4 |
import os
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
# 配置日志
|
11 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
@@ -23,6 +24,7 @@ sys.stderr = logging.getLogger().handlers[0].stream
|
|
23 |
|
24 |
try:
|
25 |
# 在try块中运行v2_3.py,并将输出重定向到日志文件
|
|
|
26 |
with open(log_file, 'a') as log_file_handle:
|
27 |
subprocess.run(['python', 'v2_3.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT)
|
28 |
except subprocess.CalledProcessError as e:
|
@@ -32,6 +34,7 @@ except Exception as e:
|
|
32 |
# 捕获其他异常并记录到日志文件
|
33 |
logging.exception(f"程序发生异常: {e}")
|
34 |
finally:
|
|
|
35 |
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
36 |
logging.getLogger().removeHandler(console_handler)
|
37 |
console_handler.close()
|
|
|
3 |
import logging
|
4 |
import os
|
5 |
|
6 |
+
# 检查是否存在 logs.txt 文件,如果存在则删除它
|
7 |
+
log_file = '/bushu/logs.txt'
|
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')
|
|
|
24 |
|
25 |
try:
|
26 |
# 在try块中运行v2_3.py,并将输出重定向到日志文件
|
27 |
+
print ("开始运行安装文件...")
|
28 |
with open(log_file, 'a') as log_file_handle:
|
29 |
subprocess.run(['python', 'v2_3.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT)
|
30 |
except subprocess.CalledProcessError as e:
|
|
|
34 |
# 捕获其他异常并记录到日志文件
|
35 |
logging.exception(f"程序发生异常: {e}")
|
36 |
finally:
|
37 |
+
print ("安装完毕!")
|
38 |
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
39 |
logging.getLogger().removeHandler(console_handler)
|
40 |
console_handler.close()
|