Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <linux/limits.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include "LineParser.h"
  9. void execute(cmdLine *pCmdLine);
  10.  
  11. int main(int argc,char **argv){
  12.  
  13. char buff_path[PATH_MAX];
  14. int q_flag = 1;
  15. getcwd(buff_path,sizeof(buff_path));
  16. /*puts inside buff_path the pathname of the current working directory of the
  17. calling process*/
  18. fprintf(stdout,"%s \n",buff_path);
  19. char commands[2048];
  20.  
  21. while(q_flag){
  22. fgets(commands,2048,stdin);
  23. struct cmdLine* cmdLine_1;
  24. cmdLine_1 =parseCmdLines(commands);
  25. if(strcmp(cmdLine_1->arguments[0],"quit")==0){
  26. q_flag=0;
  27. }
  28. if(q_flag){
  29. execute(cmdLine_1);
  30. }
  31. /*eather may we need to free mem*/
  32. freeCmdLines(cmdLine_1);
  33.  
  34. }
  35.  
  36. return(0);
  37. }
  38.  
  39. void execute(cmdLine *pCmdLine){
  40. int answer = execvp(pCmdLine->arguments[0],pCmdLine->arguments);
  41. if(answer==-1){
  42. perror("execvp");
  43. /* fprintf(stdout,"error in execvp");*/
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement