Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `[^'\n\t][^'\n\t]*` {
- int cmd_pipe[2],out_pipe[2];
- pid_t pid;
- int j=0;
- char array[strlen(yytext)+7];
- char * cmd = strdup(yytext);
- cmd++;
- cmd[strlen(cmd)-1] = '\0';
- int one = dup(0);
- int two = dup(1);
- if ((pipe(cmd_pipe) <0) || (pipe(out_pipe) <0)) {
- perror("pipe");
- exit(1);
- }
- dup2(cmd_pipe[0],0);
- dup2(out_pipe[1],1);
- write(out_pipe[1],cmd,strlen(cmd));
- write(out_pipe[1],"\nexit\n",6);
- close(out_pipe[1]);
- close(cmd_pipe[1]);
- close(cmd_pipe[0]);
- pid = fork();
- if (pid < 0) {
- perror("fork");
- exit(1);
- }
- else if (pid ==0) {
- execlp("/proc/self/exe","/proc/self/exe",NULL);
- _exit(1);
- }
- else if (pid > 0) {
- waitpid(pid,NULL,0);
- char* str =(char*) malloc((SUB_SIZE+1)*sizeof(char));
- char c;
- int i=0;
- while(read(out_pipe[0],&c,1)) {
- if (c == '\n'){
- str[i++]= ' ' ;
- }
- else {
- str[i++] = c;
- }
- }
- str[i] = '\0';
- while (i-- != 0) {
- unput(str[i]);
- }
- dup2(one,0);
- dup2(two,0);
- close(one);
- close(two);
- close(out_pipe[0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement