My own shell-wannabe

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 13
Reputation: mashimaro is an unknown quantity at this point 
Solved Threads: 0
mashimaro mashimaro is offline Offline
Newbie Poster

My own shell-wannabe

 
0
  #1
Nov 8th, 2008
Hey, I wanted to write a script that would act as a shell, meaning: would display prompt, read from keyboard and run system commands. My guess would be to use fork() and exec() and strtok(), so I wrote this:

Shell Scripting Syntax (Toggle Plain Text)
  1. #all includes <bla.h>
  2.  
  3. main(int argc, char *argv){
  4. int proces;
  5. char *line;
  6. char *cmd;
  7. int my_exec;
  8. pid_t pid;
  9.  
  10. while(1){
  11. printf("serwerX:1% ");
  12. gets(line);
  13. cmd=strtok(line," ");
  14. pid=fork();
  15. if(pid==0){
  16. my_exec=execl(cmd);
  17. if(my_exec==-1){
  18. printf("error");
  19. }
  20. exit(0);
  21. }
  22. else{
  23. sleep(1);
  24. printf("serwerX:2% ");
  25. exit(0);
  26. }
  27. }
  28. }

but, I'm not really sure how is this suppose to look like :/
Could some1 help me out?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 468 | Replies: 0
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC