Then inside the script we fork off ... We then waitpid inside the forked process

This sounds a lot like what system already does. Why do this twice?

we have found that in some cases the upgrade.pl child process starts out writing to its parent process log (do-upgrades.log), and in other instances it writes to worklog correctly as directed

Obviously, if you could narrow this down in which cases this happens (as others have pointed out, e.g. for what values of $sensor) more and make it more reproducible, that would be the best thing.

system("./upgrade.pl $sensor >> worklog 2>&1")

This kind of thing may work when $sensor is tightly controlled (see my node here!) and the system it is being run on never changes (The problem of "the" default shell), but I would still strongly recommend against it. Also, what is the first line of upgrade.pl? If it's #!/usr/bin/env perl, its execution is dependent on PATH. Anyway, if upgrade.pl is a short-lived process, then I'd recommend IPC::Run3 instead; if it is a longer process that needs to run in the background while your script continues, then IPC::Run. Both of these modules allow to avoid the shell and can still redirect STDOUT and STDERR.


In reply to Re: system() call mis-directs? by haukex
in thread system() call mis-directs? by Clarkman

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.