0

I want to pass the display of the execution of the system () function in a fifo to be able to display it on another terminal, I tried a but it gives me a segmentation fault

void executeFile(char* sourcefname,struct Info_FIFO_Transaction donnees){


    char *nomFichier, *sp;
    char command[100];
    int client_fifo_fd;
    char client_fifo[400];
    sprintf(client_fifo, CLIENT_FIFO_NAME, donnees.pid_client);
    client_fifo_fd = open(client_fifo, O_WRONLY);
    
    nomFichier = strtok_r(sourcefname, ".", &sp); 

    sprintf(command,"gcc -o fichCVSEXE%s %s.c\n",nomFichier,nomFichier);
        // execution of file
    strcat(donnees.transaction ,system(command));
    if(client_fifo_fd!=-1){
    write(client_fifo_fd, &donnees, sizeof(donnees));
        close(client_fifo_fd);}
}
essayator
  • 18
  • 5
  • [`system(command)`](https://man7.org/linux/man-pages/man3/system.3.html) returns `int`, not `char*` – IrAM Dec 23 '20 at 19:23
  • @IrAM thank you, so how to display ? – essayator Dec 23 '20 at 19:29
  • are you trying to capture the output of `system` command? – IrAM Dec 23 '20 at 19:31
  • No, I get to the display, but I don't want to display it on the terminal which executes the code, it is the server side. I want to send it to the client side by the fifo, which is another terminal, so I want to retrieve the result of the execution of the system () function which is a character string to display it on another terminal – essayator Dec 23 '20 at 19:39
  • `system` generally `fork`'s a new shell and runs the command there, so we cannot control it( at least i dont know) , better way would be to redirect the command output to a file then open the file , read it and do what ever you want to do with that content. – IrAM Dec 23 '20 at 19:40
  • yes it is good for your help – essayator Dec 23 '20 at 19:50
  • But all your command `gcc -o fichCVSEXE%s %s.c` does is just create an exe file , what do you want to send to other side? – IrAM Dec 23 '20 at 19:52
  • what the command should display – essayator Dec 23 '20 at 19:55
  • The command does not display anything (other than any compiler errors or warnings). I guess you want to send that `command` to other end , try just `strcat(donnees.transaction ,command);` after `sprintf(command,"gcc -o fichCVSEXE%s %s.c\n",nomFichier,nomFichier);` – IrAM Dec 23 '20 at 20:04

0 Answers0