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