demo01.py 500 B

1234567891011121314
  1. import subprocess
  2. # 调用script1.sh
  3. result = subprocess.run(['./script1.sh'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
  4. # 检查返回码
  5. if result.returncode == 0:
  6. print("script1.sh 执行成功")
  7. # 调用script2.sh
  8. result2 = subprocess.run(['./script2.sh'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
  9. print("script2.sh 执行成功")
  10. else:
  11. print("script1.sh 执行失败")
  12. print(f"错误输出: {result.stderr}")