Joe há 9 meses atrás
pai
commit
e4b773e09d
1 ficheiros alterados com 2 adições e 2 exclusões
  1. 2 2
      qiaojialiang/demo01.py

+ 2 - 2
qiaojialiang/demo01.py

@@ -22,7 +22,7 @@ with open(log_file, 'w') as f:
                              text=True)
 
     # 检查script1.sh的返回码,并写入输出到日志文件
-    if result1.returncode == 0:
+    if result1.returncode == 0 and not result1.stderr:
         print("script1.sh 执行成功")
         f.write(f"--- script1.sh 输出 ---\n{result1.stdout}\n")
 
@@ -30,7 +30,7 @@ with open(log_file, 'w') as f:
         result2 = subprocess.run([script2_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
 
         # 检查script2.sh的返回码,并写入输出到日志文件
-        if result2.returncode == 0:
+        if result2.returncode == 0 and not result2.stderr:
             print("script2.sh 执行成功")
             f.write(f"--- script2.sh 输出 ---\n{result2.stdout}\n")
         else: