now I have the unsettling feeling that my code hides a spurious bug

Well, that's a good argument for more defensive coding - you said that your scripts are mainly task launchers, so I'll repeat my suggestion to check all possible error conditions, or use a module to do it for you (e.g. IPC::System::Simple). One thing I'd also check is that the processes' STDOUT and STDERR is properly monitored - there are some cases where tools might exit with a code of zero, but have printed some serious warnings to STDERR. Of course it's also a good argument for writing tests for your code :-)

For example, until I wrote my own module to simplify this, I'd sometimes write code something like this:

use IPC::Run3 'run3'; sub myrun { my ($cmd) = @_; run3 $cmd, undef, \my $out, \my $err or die "run3 failed"; my $rv=$?; chomp($err); die "command '$$cmd[0]' wrote to STDERR: '$err'" if $err; die "command '$$cmd[0]' exit value indicates error: \$?=$rv" unless $rv==0; return $out; }
Surely perl has a built-in library to do the same (launching a script with a timeout/kill and return code verification).

For timeout support, you could take a look at IPC::Run.

launching a verifTomcatAdminPortal.sh ... a simple ps | grep

Note that unless you do set -e or equivalent in the shell script, you might be missing errors there, which goes against my aforementioned advice to code defensively. It's something you can do in Perl - for example, you could use IPC::System::Simple's capturex to run ps and use Perl's grep. And of course there are modules too, e.g. Proc::ProcessTable.


In reply to Re^3: problem retrieving return code of an execution with back ticks by haukex
in thread problem retrieving return code of an execution with back ticks by luxAeterna

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.