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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |