Changeset 967e3c9 for tools/repeat.c
- Timestamp:
- Jan 18, 2018, 3:06:33 PM (7 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:
- d27f609
- Parents:
- 5eba8ce
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/repeat.c
r5eba8ce r967e3c9 51 51 fprintf(out, "\t-i\t\toutput iterations instead of CMD stdout\n"); 52 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"); 53 55 exit(code); 54 56 } … … 56 58 char ** cmd_to_run = NULL; 57 59 bool print_cmd = false; 60 bool redirect = false; 61 bool redirect_append = false; 62 char * redirect_to = "/dev/null"; 58 63 pid_t child_pid = 0; 59 64 … … 74 79 75 80 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 ) { 77 82 switch ( c ) { 78 83 case Help: … … 88 93 case 'i': 89 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++; 90 107 break; 91 108 default: … … 143 160 printf("\n"); 144 161 } 145 if(print_iterations ) {162 if(print_iterations || redirect || redirect_append) { 146 163 __attribute__((unused)) FILE * ignore = 147 freopen( "/dev/null", "w", stdout);164 freopen(redirect_to, redirect_append ? "a" : "w" , stdout); 148 165 } 149 166 execvp ( *cmd_to_run, cmd_to_run);
Note: See TracChangeset
for help on using the changeset viewer.