Last active
January 30, 2024 16:14
-
-
Save clementi/30534929a1df6c293b64328444c627be to your computer and use it in GitHub Desktop.
Run a shell command repeatedly until it fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import subprocess | |
from sys import argv | |
def main(): | |
if len(argv) < 2: | |
print('Usage: {} <shell command>'.format(argv[0])) | |
exit(1) | |
run = 1 | |
while True: | |
print('########## Run {} ##########'.format(run)) | |
return_code = subprocess.run(argv[1:]).returncode | |
if return_code != 0: | |
print('########## Error code {} ##########'.format(return_code)) | |
break | |
run += 1 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment