3 Replies Latest reply on Feb 27, 2019 8:51 PM by user9130018

    Tuxedo and popen

    Mats Ulvedal

      I need to perform popen() in a tuxedo server.

       

      It just not work, the more or less same code works fine in my own environment in simple C program (No Tuxedo involved).

      And if I copy same code into a tuxedo server (service) nothing happend, no error from either popen or fgets.

      Just nothing.

      I guess it has something to do with stdout or stdin, but that is just a guess.

       

      Anyone with some idea?

       

      Best Regards

      Mats

        • 1. Re: Tuxedo and popen
          user9130018

          hello

           

          What is your tuxedo version and platform? can you show us some example code snippet? have you tried to trace your program using system tools (truss on aix, strace on linux)?

          • 2. Re: Tuxedo and popen
            Mats Ulvedal

            Hi, sorry for late answer. I got sick.

            Below code (not exactly, but the popen stuff is copy paste) have I test in Version 12.1.3.0.0, 64-bit, Patch Level 105 and it working,

            line is empty.

             

            But it forks fine as is.

             

            No, I have not yet traced it, more then some own output here and there.

            I will do that soon.

             

            #include <string.h>
            #include <stdio.h>
            #include <stdlib.h>
            #include <errno.h>

            int main(void)
            {
                    FILE * pf = NULL;
                    char path2lastMonth[64+1] = "/home/nfs/ex12107/projects/plex/plex_december.txt";
                    char path2monthBeforeLast[64+1] = "/home/nfs/ex12107/projects/plex/plex_november.txt";

                    char line[3+1] = "";
                    char wc_line[256+1] = "";
                    char wc_line_beforeLast_cmd[256+1] = "wc -l /home/nfs/ex12107/projects/plex/plex_november.txt | awk '{print $1}'";
                    char wc_line_last_cmd[256+1] = "wc -l /home/nfs/ex12107/projects/plex/plex_december.txt | awk '{print $1}'";

                    int line_count_beforeLast = 0;
                    int line_count_Last = 0;

                    /*
                    memset(line, '\0', sizeof(line));
                    pf = popen(wc_line_beforeLast_cmd, "r");
                    if (pf != NULL) {
                            while (fgets(line, 3+1, pf) != NULL) {
                                    line_count_beforeLast = atoi(line);
                                    pclose(pf);
                            }
                    }else{
                            (void)printf("popen failed!\n");
                            exit(EXIT_FAILURE);
                            }*/

                    pf = popen(wc_line_beforeLast_cmd, "r");
                    if (pf != NULL) {
                      while (fgets(wc_line, 3, pf) != NULL) {
                        line_count_beforeLast = atoi(wc_line);
                        pclose(pf);
                      }
                    }else{
                      (void)printf("popen failed!\n");
                      exit(EXIT_FAILURE);

                    }

                    memset(line, '\0', sizeof(line));
                    pf = popen(wc_line_last_cmd, "r");
                    if (pf != NULL) {
                            while (fgets(line, 3+1, pf) != NULL) {
                                    line_count_Last = atoi(line);
                                    pclose(pf);
                            }
                    }else{
                            (void)printf("popen failed!\n");
                            exit(EXIT_FAILURE);
                    }

                    printf("line_count_beforeLast %d, line '%s'\n", line_count_beforeLast, line);
                    printf("line_count_Last %d, line '%s'\n", line_count_Last, line);

                    return(0);
            }

             

            Thanks

            Mats

            • 3. Re: Tuxedo and popen
              user9130018

              Some issues with example:

              - you pclose stream inside reading loop - please move this closing outside

              - increasing size of "line" variable and using sizeof in fgets might be good idea

              It should work now