Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active December 11, 2015 15:38
Show Gist options
  • Save Heimdell/4621879 to your computer and use it in GitHub Desktop.
Save Heimdell/4621879 to your computer and use it in GitHub Desktop.
Do it again.
int main(int argc, char *argv[]) {
int count = 10, silent = 0;
char * command = 0;
char letter;
while ((letter = getopt_long(argc, argv, "n:c:s")) != -1) {
switch (letter) {
case 'n':
count = atoi(optarg);
break;
case 'c':
command = optarg;
break;
case 's':
silent = 1;
}
}
if (!command) {
printf("USAGE: retry [-n <number>] -c <command> [-s]\n");
}
int result = -1;
while (count--) {
result = system(command);
if (!result) break;
if (!silent) {
printf("\nexecution result was %d\n%d more times...\n\n", result, count);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment