Here is the background info you requested. I am basically trying to call a Perl script from within a C program. However, I don't want to just make a system() call. I want to be able to capture the output (stdout) from the Perl script. If I run the Perl script on it's own, I get the output displayed to stdout. If I call it from the C program I do not. At first I thought this was a problem with my C program, but I am pretty sure it is not. Why? Because if I assign a random string (aka "Hello World") to a variable in that same Perl script and execute a print command from inside it, THEN my C program is able to capture the output from stdout. But if I use the "print $res->decode_content" command it does not. Just for clarification, here is a portion of the C program:

char command[] = "/home/user/scripts/PerlScript.pl"; . . fp = popen(command, "r"); buffer = (char *)malloc(sizeof(char) * bufSize); while( fgets(buffer, bufSize, fp) != NULL) fputs(buffer, stdout); pclose(fp); free(buffer);

The above program calls the Perl script I have written that is in question. Again, if I do the following it prints when called from the C program:

my $randomVar = "Hello World\n"; print $randomVar;

But if I do this, it will NOT print from the C program (unless I call the Perl script by itself from the command line):

my $res = $ua->get('http://SOMEURLHERE'); print $res->decoded_content;

In reply to Re^8: Cannot access HTTP::Response content properly by URAvgDeveloper101
in thread Cannot access HTTP::Response content properly by URAvgDeveloper101

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.