Tuxedo and popen — oracle-tech

    Forum Stats

  • 3,715,753 Users
  • 2,242,856 Discussions
  • 7,845,550 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tuxedo and popen

Mats Ulvedal
Mats Ulvedal Member Posts: 85
edited February 2019 in Tuxedo

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

Answers

  • user9130018
    user9130018 Member Posts: 77 Blue Ribbon
    edited February 2019

    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)?

  • Mats Ulvedal
    Mats Ulvedal Member Posts: 85
    edited February 2019

    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

  • user9130018
    user9130018 Member Posts: 77 Blue Ribbon
    edited February 2019

    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

Sign In or Register to comment.