Do I have this straight?

From one running perl program, you want to invoke a second copy of perl running a second, pre-existing perl program, pass it a 3rd perl program, in the form of a single string, that it will then pass to a 3rd copy of perl to run.

And the problems you are having are:

  1. How to pass a single(?) switch from the first program to the second so that it can give it to the third copy of perl as a command line argument.

    Assuming $arg was 'x', this :open(my $fh,'|-', 'perl', '-', $arg); is equivalent to typing this at the command line:

    perl - x

    Which is obviously wrong. Try: open(my $fh,'|-', 'perl', "-$arg" );

  2. How to capture the STDERR output.

    From which instance of Perl?

    You are invoking the second copy of perl with command line redirection, which means the first program should receive all stdout and stderr output from the second.

    But any output from the third instance of perl will be going to its (virtual) console. Is it the STDERR output from this process you are having trouble capturing?

    Because without trying it out, I could not even guess aa to what would happen to it on my OS; never mind on any other. At that point you have a hierarchy of processes like this:

    <someshell> +-- perl +-- <someshell> (because of the command line redirection used +in backticks in the first program.) +-- perl +-- perl

    And you are hoping the command line redirection in second level of shell, will capture both stdout & stderr output from the third level of perl.

One question: why? (Including, but not limited to:why not just embed the 10 lines of code in second perl program in the first? Wrapped over as a function if necessary.)

Another question: Could you post an example of the program that is being fed to the 3rd level perl?

Update:Another question: Why? :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: running string as perl script and pass into STDIN programatically by BrowserUk
in thread running string as perl script and pass into STDIN programatically by gideondsouza

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.