Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int checkforP(char** command,int* pos){
- int len = strlen(command);
- int c;
- for(int i = 0; i < len; i++){
- *pos = i;
- c = strcmp(command[i],">");
- if(c == 0){
- //printf("%d\n", i);
- return 1;}
- }
- return 0;
- }
- void write2file(char **command, int position){
- int fd;
- int rec;
- int savedout = dup(1);
- fd = open(command[position+1],O_CREAT|O_WRONLY|O_TRUNC,0660);
- if(fd==-1){
- printf("Failed to open file\n" );
- return;
- }
- rec = dup2(fd,1);
- if(rec < 0){
- printf("Dup2 Failed");
- }
- for(int i = 0; i < position; i++){
- printf("%s ",command[i]);
- }
- dup2(savedout,1);
- close(fd);
- printf("Stop\n" );
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement