Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1.  
  2. int checkforP(char** command,int* pos){
  3.   int len = strlen(command);
  4.   int c;
  5.   for(int i = 0; i < len; i++){
  6.     *pos = i;
  7.     c = strcmp(command[i],">");
  8.     if(c == 0){
  9.       //printf("%d\n", i);
  10.       return 1;}
  11.   }
  12.   return 0;
  13. }
  14.  
  15.  
  16. void write2file(char **command, int position){
  17.   int fd;
  18.   int rec;
  19.   int savedout = dup(1);
  20.   fd = open(command[position+1],O_CREAT|O_WRONLY|O_TRUNC,0660);
  21.   if(fd==-1){
  22.     printf("Failed to open file\n" );
  23.    return;
  24.   }
  25.   rec = dup2(fd,1);
  26.   if(rec < 0){
  27.     printf("Dup2 Failed");
  28.   }
  29.   for(int i = 0; i < position; i++){
  30.     printf("%s ",command[i]);
  31.   }
  32.   dup2(savedout,1);
  33.   close(fd);
  34.   printf("Stop\n" );
  35.   return;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement