Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- void error(){
- printf("Use [--parameter] [argument]\n");
- printf("'console' for stdout/stderr to console\n");
- printf("'file' for stdout/stderr to file\n");
- }
- int main(int argc, char **argv){
- if (argc <= 2){
- printf("More arguments are required\n");
- printf("empty\n");
- error();
- return 1;
- }
- else if (argc == 3){
- if (memcmp(argv[1], "--console", 10) == 0){
- char command[100] = "exec 2<&-; exec 2>&1;";
- strcat(command, argv[2]);
- strcat(command, "; echo \"Status code: $?\"");
- system(command);
- }
- else if (memcmp(argv[1], "--file", 6) == 0){
- char command[100] = "touch out_script.txt; exec 1<&-; exec 2<&-; exec 1<>out_script.txt; exec 2>&1;";
- strcat(command, argv[2]);
- strcat(command, "; echo \"Status code: $?\"");
- system(command);
- }
- else{
- printf("Wrong parameters\n%s\n", argv[1]);
- error();
- return 1;
- }
- }
- else{
- printf("Too many arguments\n");
- error();
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement