Changes in / [35a4b94d:d27f609]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/repeat.c

    r35a4b94d rd27f609  
    5151        fprintf(out, "\t-i\t\toutput iterations instead of CMD stdout\n");
    5252        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");
    5355        exit(code);
    5456}
     
    5658char ** cmd_to_run = NULL;
    5759bool print_cmd = false;
     60bool redirect = false;
     61bool redirect_append = false;
     62char * redirect_to = "/dev/null";
    5863pid_t child_pid = 0;
    5964
     
    7479
    7580        int c;
    76         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 ) {
    7782                switch ( c ) {
    7883                        case Help:
     
    8893                        case 'i':
    8994                                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++;
    90107                                break;
    91108                        default:
     
    143160                        printf("\n");
    144161                }
    145                 if(print_iterations) {
     162                if(print_iterations || redirect || redirect_append) {
    146163                        __attribute__((unused)) FILE * ignore =
    147                                 freopen("/dev/null", "w", stdout);
     164                                freopen(redirect_to, redirect_append ? "a" : "w" , stdout);
    148165                }
    149166                execvp ( *cmd_to_run, cmd_to_run);
Note: See TracChangeset for help on using the changeset viewer.