python.subprocess.cpp 991 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. /**
  5. # always to print to stdout and stderr.
  6. g++ python.subprocess.cpp -o python.subprocess
  7. */
  8. int main(int argc, char** argv) {
  9. if (argc <= 2) {
  10. printf("Usage: <%s> <interval_ms> <max_loop>\n"
  11. " %s 50 100000\n", argv[0], argv[0]);
  12. exit(-1);
  13. return -1;
  14. }
  15. int interval_ms = ::atoi(argv[1]);
  16. int max_loop = ::atoi(argv[2]);
  17. printf("always to print to stdout and stderr.\n");
  18. printf("interval: %d ms\n", interval_ms);
  19. printf("max_loop: %d\n", max_loop);
  20. for (int i = 0; i < max_loop; i++) {
  21. fprintf(stdout, "always to print to stdout and stderr. interval=%dms, max=%d, current=%d\n", interval_ms, max_loop, i);
  22. fprintf(stderr, "always to print to stdout and stderr. interval=%dms, max=%d, current=%d\n", interval_ms, max_loop, i);
  23. if (interval_ms > 0) {
  24. usleep(interval_ms * 1000);
  25. }
  26. }
  27. return 0;
  28. }