Hi all, I am having trouble with a perl open pipe where it seems to exiting from the called script early for some users. I have a script that talks to an SQL database, but before it even tries to communicate with the SQL database I have it printing a message stating that the script has started running:

# Subscript PrintLog("My sub-script is running...","i"); PrintLog("Yes, just to confirm I am running...","i"); ...etc...onto the SQL stuff

My main script then calls this as follows:

my $run_pid = open(RUN, "sub_script.pl $options 2>&1 |") or $sub_fai +led = 1; if (!$sub_failed) { $text .= "Entered if (!\$sub_failed) {\n"; while (<RUN>) { $text .= "Entered while (<RUN>)\n"; chomp; $_ =~ s/^\s*//; $text .= "$_\n"; } close(RUN); if ($? != 0) { $sub_failed = 1; } } else { $text .= "Failed to open sub_script.pl\n";} print "$text";
The problem I am seeing is that the print of text at the end can sometimes return any of the following:
Entered if (!\$sub_failed) { or Entered if (!\sub_failed) { Entered while (<RUN>) or Entered if (!\$sub_failed) { Entered while (<RUN>) My sub-script is running... or Entered if (!\$sub_failed) { Entered while (<RUN>) My sub-script is running... Yes, just to confirm I am running.. and so on...

I am struggling to figure out what my be the cause of thinking the pipe is finished early. I have use piped opens in several places without issue so originally though that the issue was a due to a delay in connecting to the SQL server but the prints show that things can fall over even before I get to the SQL part of things.

Any advice/direction would be appreciated.

Thanks

Albob


In reply to Perl open pipe exiting early by albob

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.