Run a system command and ensure it succeeds.
(command, shell=False, log_step=None)
| 6 | import subprocess |
| 7 | |
| 8 | def run_command(command, shell=False, log_step=None): |
| 9 | """Run a system command and ensure it succeeds.""" |
| 10 | if log_step: |
| 11 | log_file = os.path.join(args.log_dir, log_step + ".log") |
| 12 | with open(log_file, "w") as f: |
| 13 | try: |
| 14 | subprocess.run(command, shell=shell, check=True, stdout=f, stderr=f) |
| 15 | except subprocess.CalledProcessError as e: |
| 16 | logging.error(f"Error occurred while running command: {e}, check details in {log_file}") |
| 17 | sys.exit(1) |
| 18 | else: |
| 19 | try: |
| 20 | subprocess.run(command, shell=shell, check=True) |
| 21 | except subprocess.CalledProcessError as e: |
| 22 | logging.error(f"Error occurred while running command: {e}") |
| 23 | sys.exit(1) |
| 24 | |
| 25 | def run_benchmark(): |
| 26 | build_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "build") |