| import subprocess | |
| # 定义 shell 脚本的路径 | |
| script_path = '/home/user/app/a.sh' | |
| # 使用 subprocess.run 来运行 shell | |
| result = subprocess.run(['bash', script_path], capture_output=True, text=True) | |
| # 打印输出和错误 | |
| print("Output:", result.stdout) | |
| print("Error:", result.stderr) | |
| # 检查返回码 | |
| if result.returncode == 0: | |
| print("Script executed successfully") | |
| else: | |
| print("Script execution failed with return code:", result.returncode) |