Changes in tools/repeat.c [967e3c9:4149d9d]
- File:
-
- 1 edited
-
tools/repeat.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tools/repeat.c
r967e3c9 r4149d9d 26 26 if(print_iterations) { 27 27 printf("\r%d / %d", i, repetitions); 28 fflush(stdout);29 28 } 30 29 int retcode = run(); … … 48 47 fprintf(out, "Repeat CMD N times\n\n"); 49 48 fprintf(out, "\t-h,--help\tprint this usage message\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"); 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"); 55 52 exit(code); 56 53 } … … 58 55 char ** cmd_to_run = NULL; 59 56 bool print_cmd = false; 60 bool redirect = false;61 bool redirect_append = false;62 char * redirect_to = "/dev/null";63 57 pid_t child_pid = 0; 64 58 … … 79 73 80 74 int c; 81 while ( (c = getopt_long( argc, argv, " ahirsx", long_opts, &long_index)) != -1 ) {75 while ( (c = getopt_long( argc, argv, "hsxi", long_opts, &long_index)) != -1 ) { 82 76 switch ( c ) { 83 77 case Help: … … 93 87 case 'i': 94 88 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++;107 89 break; 108 90 default: … … 160 142 printf("\n"); 161 143 } 162 if(print_iterations || redirect || redirect_append) {144 if(print_iterations) { 163 145 __attribute__((unused)) FILE * ignore = 164 freopen( redirect_to, redirect_append ? "a" : "w", stdout);146 freopen("/dev/null", "w", stdout); 165 147 } 166 148 execvp ( *cmd_to_run, cmd_to_run);
Note:
See TracChangeset
for help on using the changeset viewer.