You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_runner.c 652 B

123456789101112131415161718192021222324
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, char *argv[]) {
  4. if (argc != 2 && argc != 3) {
  5. fprintf(stderr, "Usage: %s <executable> <optional_input_file>\n", argv[0]);
  6. return EXIT_FAILURE;
  7. }
  8. char command[1024];
  9. if (argc == 2) {
  10. snprintf(command, sizeof(command), "%s", argv[1]);
  11. } else {
  12. snprintf(command, sizeof(command), "%s < %s", argv[1], argv[2]);
  13. }
  14. int result = system(command);
  15. if (result != EXIT_SUCCESS) {
  16. fprintf(stderr, "Error: Command '%s' failed with return code %d.\n", command, result);
  17. return EXIT_FAILURE;
  18. }
  19. return EXIT_SUCCESS;
  20. }