I have made a simple shell (right not it doesn't do everything i want it to, but it interprets the dir dos command in unix...and it will do the same for copy and a few more soon) but, n e wayz, i just want to know why after i execute a command i have to hit enter again to get the prompt. I have no idea why, could someone take a look @ my code, it's short and simple.
Thanks Matt.D
Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int status;
pid_t pid;
char command[BUFSIZ];
//Convert Unix ls to Dos dir
const char *s1 = "dir";
const char *s2 = "ls";
while(1){
printf("Matt-shell> ");
if (fgets(command, sizeof(command), stdin) == NULL) {
putchar('\n');
exit(0);
}
command[strlen(command)-1] = NULL;
if((pid = fork()) == 0){
if(strcmp(command,s1) == 0)
{
execlp(s2,s2,0); // Executes Dos Interpreted Commands
}
system(command); // Executes everything else
while (wait(&status) != pid )
continue;
putchar('\n');
}
}
}
Thanks Matt.D