BBrother commited on
Commit
a3ddf5f
1 Parent(s): 7452a8e

Update SW_run.py

Browse files
Files changed (1) hide show
  1. SW_run.py +17 -2
SW_run.py CHANGED
@@ -8,6 +8,11 @@ log_file = '/bushu/logs_run.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')
13
 
@@ -27,8 +32,18 @@ subprocess.run(["cd", "/bushu/ui"], shell=True)
27
 
28
  try:
29
  # 在try块中运行v2_3.py,并将输出重定向到日志文件
30
- with open(log_file, 'a') as log_file_handle:
31
- subprocess.run(['python', 'launch.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT)
 
 
 
 
 
 
 
 
 
 
32
  except subprocess.CalledProcessError as e:
33
  # 捕获异常并记录到日志文件
34
  logging.exception(f"程序发生异常: {e}")
 
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
 
 
32
 
33
  try:
34
  # 在try块中运行v2_3.py,并将输出重定向到日志文件
35
+ with open(log_file, 'a') as log_file_handle, open(url_file, 'a') as url_file_handle:
36
+ process = subprocess.Popen(['python', 'launch.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
37
+ for line in process.stdout:
38
+ if "Running on" in line:
39
+ # 如果日志行包含 "Running on",将它写入 url.txt 文件
40
+ url_file_handle.write(line)
41
+ else:
42
+ # 否则,将日志行写入 logs_run.txt 文件
43
+ log_file_handle.write(line)
44
+ log_file_handle.flush()
45
+ url_file_handle.flush()
46
+ process.wait()
47
  except subprocess.CalledProcessError as e:
48
  # 捕获异常并记录到日志文件
49
  logging.exception(f"程序发生异常: {e}")