Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/repeat.c

    r967e3c9 r4149d9d  
    2626                if(print_iterations) {
    2727                        printf("\r%d / %d", i, repetitions);
    28                         fflush(stdout);
    2928                }
    3029                int retcode = run();
     
    4847        fprintf(out, "Repeat CMD N times\n\n");
    4948        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");
    5552        exit(code);
    5653}
     
    5855char ** cmd_to_run = NULL;
    5956bool print_cmd = false;
    60 bool redirect = false;
    61 bool redirect_append = false;
    62 char * redirect_to = "/dev/null";
    6357pid_t child_pid = 0;
    6458
     
    7973
    8074        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 ) {
    8276                switch ( c ) {
    8377                        case Help:
     
    9387                        case 'i':
    9488                                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++;
    10789                                break;
    10890                        default:
     
    160142                        printf("\n");
    161143                }
    162                 if(print_iterations || redirect || redirect_append) {
     144                if(print_iterations) {
    163145                        __attribute__((unused)) FILE * ignore =
    164                                 freopen(redirect_to, redirect_append ? "a" : "w" , stdout);
     146                                freopen("/dev/null", "w", stdout);
    165147                }
    166148                execvp ( *cmd_to_run, cmd_to_run);
Note: See TracChangeset for help on using the changeset viewer.