from pathlib import Path
import json, subprocess
root=Path(__file__).parent
results=[]
for command in json.loads((root/'hardware-commands.json').read_text()):
 name=Path(command[1]).stem
 with (root/(name+'.hardware.log')).open('w') as log:
  result=subprocess.run(command, stdout=log, stderr=subprocess.STDOUT)
 results.append({'case':name,'exit_code':result.returncode})
 (root/'hardware-results.json').write_text(json.dumps(results,indent=2)+'\n')
 print(results[-1],flush=True)
 if result.returncode:raise SystemExit(result.returncode)
