c - Streaming execvp output via socket -


i know question has been asked billion times, solutions not working me. need stream stdout of execvp via socket client. relevant client code this

static void execute_cmd(int fd, char *cmd, char **params) {     pid_t cid;     size_t = 0, c = 0;      cid = fork();      if(cid == 0) {         close(stdout_fileno);         dup2(fd, stdout_fileno);          if(execvp(cmd, params) < 0) {             fprintf(stderr, "could not execute \"%s\": %d\n", cmd, errno);             exit(1);         }     } else {         close(fd);         waitpid(cid, null, 0);         exit(1);     } } 

i have tried copy answer on this question. however, nothing when try code:

int sockfd = serverconnect(); write(sockfd, "echo math", 11); n = read(sockfd, buffer, 1023);  printf("got %d bytes\n", n); printf("%s\n", buffer);  close(sockfd); 

i triple checked connection established correctly. when replace execute_cmd simple write, client correctly prints answer. nothing happens when execute code above, no bytes back. have removed dup2 call , got no output execvp call either.

getting quite desperate here, tried pipe , whatever find. did go wrong? command ok, too, works on shell, , execvp call not throw error.

turns out code above correct. problem incorrect use of earlier strtok resulted in silent crash of strdup. fork above never executed, , tests above strtok line. after putting printfs every line of code find problem.

frankly, feel stupid.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -