rendered paste body#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>
void parser(char* buf, char** args) ;
void execution(char** args) ;
main()
{
char buf[1024];
char* args[64];
for(;;)
{
printf("Command:\n"); //παίρνει εντολή από χρήστη
if(fgets(buf, sizeof(buf),stdin)==NULL)
{
printf("\n"); exit(0);
}
parser(buf,args);
execution(args);
}
}
void parse(char* buf, char** args)
{
while (*buf != '\0')
{
while((*buf==' ')||(*buf=='\t')||(*buf=='\n'))
{
*buf++ = '\0';
}
*args++=buf; //σώζεις arguments
while ((*buf!='\0') && (*buf!=' ') && (*buf!='\t') && (*buf!='\n'))
{
buf++;
}
}
*--args = NULL;
}
void execution(char** args)
{
int pid, status ;
if((pid=fork())<0)
{
perror("fork"); exit(1);
}
if(pid==0)
{
execvp(*args,args);
perror("*args");
exit(1);
}
while (wait(&status)!=pid);
}