42-archive/ftp/srcs/serv_do_sh.c
2017-07-25 18:20:34 +02:00

23 lines
382 B
C

#include "ft_p.h"
int serv_do_sh(int sock)
{
char command[MAXLINE];
int ret;
if ((ret = read(sock, command, MAXLINE)) < 0)
return (CMD_FAIL);
command[ret] = 0;
DG("received '%s' command", command);
if (fork() == 0)
{
dup2(sock, 1);
system(command);
exit(0);
}
DG("waiting for command");
wait(0);
DG("finished waiting for command");
return (CMD_SUCCESS);
}