Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commands[0][0] = command
- commands[0][1] = arg1
- commands[0][2] = arg2
- commands[1][0] = command
- commands[2][0] = command
- commands[2][1] = arg1
- int _pipe(char* input){
- char** commands[MAX_STRING];
- char temp_command[MAX_STRING];
- char* args[MAX_ARGS];
- int args_size = 0;
- int total_commands = 0;
- int start = 0;
- for(int i = 0; i < strlen(input); i++){
- if(input[i] == '|' || (start != 0 && i == strlen(input) - 1)){
- memcpy(temp_command, &input[start], (size_t) i);
- temp_command[i] = 0;
- commands[total_commands++] = tokenize(temp_command, &args_size);
- //I suspect this line is the culprit, but I don't know any alternative
- //Also, tokenize just returns a string array. I'm passing args_size because I needed to pass it by reference in another function.
- start = i+1;
- }
- }
- for(int i = 0; i < total_commands; i++)
- printf("ncommand start: [%s]", commands[i][0]);
- return 0;
- }
- > command1 | command2
- command start: [command2]
- command start: [command2]
- > command1 | command2
- command start: [command1]
- command start: [command2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement