how to show the result of execvp in client

0

I have more this code in my server program: if (! fork ()) {     dup2 (sockClie, 0); // stdin     dup2 (sockclie, 1); // stdout     close (sockClie);     execvp (arg, arg); }

What I want is for the server to ask me for the commands to my clilenet program and then show the result in the client. My server program works with telnet perfectly but not with my client program. How would I have to improve my client program? thanks

while(1)
{
    tam_cliente=sizeof cliente;
    sock_cliente=accept(sock_servidor,(struct sockaddr *)&cliente,&tam_cliente);
    if(sock_cliente<0)
    {
        perror("acceptando cliente");
        return -1;
    }

    ip_cliente=inet_ntoa(cliente.sin_addr);
    puerto_cliente=ntohs(cliente.sin_port);
    printf("cliente conectado:%s:%d\n",ip_cliente,puerto_cliente);
    memset(mensaje_cliente,0,sizeof mensaje_cliente);
    //read(sock_cliente,&mensaje_cliente,sizeof mensaje_cliente);
    //printf("mensaje cliente:%s\n",mensaje_cliente);
    if(!fork())
    {
        printf("inicio fork\n");
        close(sock_servidor);
        dup2(sock_cliente,0);
        dup2(sock_cliente,1);
        close(sock_cliente);
        printf("introdusca comando:\n");
        fgets(mensaje_cliente,20,stdin);
        printf("mensaje_cliente=\n%s",mensaje_cliente);
        char *com[]={"ls","-l",NULL};
                    execvp(com[0],com);
        exit(1);
    }
    close(sock_cliente);
}

works fine with telnet but it does not work with the client program that I did just connect and supposedly as it is doing dup2 with stdin and stdout I repeat it works fine with telnet

    
asked by Daniel Ramos 20.03.2018 в 18:21
source

0 answers