Changeset 7416d46a for tools/repeat.c
- Timestamp:
- Jan 30, 2018, 3:54:32 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 633a642
- Parents:
- f792cb8 (diff), 42be3c3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/repeat.c
rf792cb8 r7416d46a 26 26 if(print_iterations) { 27 27 printf("\r%d / %d", i, repetitions); 28 fflush(stdout); 28 29 } 29 30 int retcode = run(); … … 47 48 fprintf(out, "Repeat CMD N times\n\n"); 48 49 fprintf(out, "\t-h,--help\tprint this usage message\n"); 49 fprintf(out, "\t-s\tstop on error\n"); 50 fprintf(out, "\t-i\toutput iterations instead of CMD stdout\n"); 51 fprintf(out, "\t-x\tprint CMD before running it\n"); 50 fprintf(out, "\t-s\t\tstop on error\n"); 51 fprintf(out, "\t-i\t\toutput iterations instead of CMD stdout\n"); 52 fprintf(out, "\t-x\t\tprint CMD before running it\n"); 53 fprintf(out, "\t-a FILE\t\tredirect output of command to append to FILE\n"); 54 fprintf(out, "\t-r FILE\t\tredirect output of command to FILE\n"); 52 55 exit(code); 53 56 } … … 55 58 char ** cmd_to_run = NULL; 56 59 bool print_cmd = false; 60 bool redirect = false; 61 bool redirect_append = false; 62 char * redirect_to = "/dev/null"; 57 63 pid_t child_pid = 0; 58 64 … … 73 79 74 80 int c; 75 while ( (c = getopt_long( argc, argv, " hsxi", long_opts, &long_index)) != -1 ) {81 while ( (c = getopt_long( argc, argv, "ahirsx", long_opts, &long_index)) != -1 ) { 76 82 switch ( c ) { 77 83 case Help: … … 87 93 case 'i': 88 94 print_iterations = true; 95 break; 96 case 'a': 97 if(redirect) { fprintf(stderr, "Cannot have -a and -r\n"); error(); } 98 redirect_append = true; 99 redirect_to = argv[optind]; 100 optind++; 101 break; 102 case 'r': 103 if(redirect_append) { fprintf(stderr, "Cannot have -a and -r\n"); error(); } 104 redirect = true; 105 redirect_to = argv[optind]; 106 optind++; 89 107 break; 90 108 default: … … 142 160 printf("\n"); 143 161 } 144 if(print_iterations ) {162 if(print_iterations || redirect || redirect_append) { 145 163 __attribute__((unused)) FILE * ignore = 146 freopen( "/dev/null", "w", stdout);164 freopen(redirect_to, redirect_append ? "a" : "w" , stdout); 147 165 } 148 166 execvp ( *cmd_to_run, cmd_to_run);
Note:
See TracChangeset
for help on using the changeset viewer.