| 
					
				 | 
			
			
				@@ -15,16 +15,27 @@ n2 = 5 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 script1_path = "./script1.sh" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 script2_path = "./script2.sh" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+# 打开日志文件准备写入 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 with open(log_file, 'w') as f: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 调用script1.sh 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    result = subprocess.run([script1_path, str(n1), str(n2)], shell=True, stdout=f, stderr=subprocess.STDOUT) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 调用script1.sh,不使用shell=True 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    result1 = subprocess.run([script1_path, str(n1), str(n2)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                             text=True) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 检查返回码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if result.returncode == 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 检查script1.sh的返回码,并写入输出到日志文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if result1.returncode == 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print("script1.sh 执行成功") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # 调用script2.sh 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        result2 = subprocess.run([script2_path], shell=True, stdout=f, stderr=subprocess.STDOUT) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print("script2.sh 执行成功") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        f.write(f"--- script1.sh 输出 ---\n{result1.stdout}\n") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        # 调用script2.sh,同样不使用shell=True 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result2 = subprocess.run([script2_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        # 检查script2.sh的返回码,并写入输出到日志文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if result2.returncode == 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            print("script2.sh 执行成功") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.write(f"--- script2.sh 输出 ---\n{result2.stdout}\n") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            print("script2.sh 执行失败") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            f.write(f"--- script2.sh 错误输出 ---\n{result2.stderr}\n") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print("script1.sh 执行失败") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(f"错误输出: {result.stderr}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        f.write(f"--- script1.sh 错误输出 ---\n{result1.stderr}\n") 
			 |