Skip to content

Instantly share code, notes, and snippets.

@clementi
Last active January 30, 2024 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clementi/30534929a1df6c293b64328444c627be to your computer and use it in GitHub Desktop.
Save clementi/30534929a1df6c293b64328444c627be to your computer and use it in GitHub Desktop.
Run a shell command repeatedly until it fails
#! /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