Advertisement
Guest User

fake-shell.c

a guest
May 23rd, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define BUFFER 4096
  5. #define RUN_FOREVER 1
  6.  
  7. int main(int argc , char * argv[] )
  8. {
  9.     char input[BUFFER];
  10.  
  11.     //Get always a command line from the user.
  12.     while(RUN_FOREVER)
  13.     {
  14.         char *stringBeforeAmpersand = NULL;
  15.         char ch;
  16.  
  17.         if (isatty(0))
  18.         {
  19.             // input is from terminal
  20.             // need to put something here
  21.         }
  22.  
  23.         printf("$ ");
  24.         memset(input, '\0', BUFFER);
  25.  
  26.         scanf("%[^\n]",input);
  27.         scanf("%c",&ch);
  28.  
  29.         if(0 == strcmp(input, "exit"))
  30.             break;
  31.  
  32.         //Separate the command according to the "&".
  33.         stringBeforeAmpersand = strtok( input, "&");
  34.         fprintf (stderr, "%s\n",stringBeforeAmpersand);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement