Skip to content

Instantly share code, notes, and snippets.

@t27
Created June 13, 2017 10:02
Show Gist options
  • Save t27/d2b514a90e74bc8588c5a6d31edab824 to your computer and use it in GitHub Desktop.
Save t27/d2b514a90e74bc8588c5a6d31edab824 to your computer and use it in GitHub Desktop.
Run a command continously (Reloads a command/program if it crashes)
#!/usr/bin/env python
import signal
import sys
import os
import subprocess
process = 0
if len(sys.argv[:])<2:
print "USAGE: python runner.py \"<your execution statement>\" \nQuotes are only necessary of you want to do redirection or something like that"
else:
while(True):
cmd = ' '.join(sys.argv[1:])
print("Launching APP - " + cmd)
process = subprocess.Popen(cmd, shell=True)
process.communicate()
@t27
Copy link
Author

t27 commented Jun 13, 2017

Usage

> python runner.py ./my_infinitely_running_app --argformyapp

Everything after runner.py will be executed indefinitely(until Ctrl-C is pressed). If the command ends/crashes, it will be reloaded.

sysout for the command will be sent to the parent scripts sysout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment