Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. void error(){
  6. printf("Use [--parameter] [argument]\n");
  7. printf("'console' for stdout/stderr to console\n");
  8. printf("'file' for stdout/stderr to file\n");
  9. }
  10.  
  11. int main(int argc, char **argv){
  12. if (argc <= 2){
  13. printf("More arguments are required\n");
  14. printf("empty\n");
  15. error();
  16. return 1;
  17. }
  18.  
  19. else if (argc == 3){
  20. if (memcmp(argv[1], "--console", 10) == 0){
  21. char command[100] = "exec 2<&-; exec 2>&1;";
  22. strcat(command, argv[2]);
  23. strcat(command, "; echo \"Status code: $?\"");
  24. system(command);
  25. }
  26. else if (memcmp(argv[1], "--file", 6) == 0){
  27. char command[100] = "touch out_script.txt; exec 1<&-; exec 2<&-; exec 1<>out_script.txt; exec 2>&1;";
  28. strcat(command, argv[2]);
  29. strcat(command, "; echo \"Status code: $?\"");
  30. system(command);
  31. }
  32. else{
  33. printf("Wrong parameters\n%s\n", argv[1]);
  34. error();
  35. return 1;
  36. }
  37. }
  38. else{
  39. printf("Too many arguments\n");
  40. error();
  41. return 1;
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement