Dear monks, novices, postulants, aspirants, benefactors,...

I have a Perl script which submits several jobs to an SGE grid cluster, later jobs being dependent on the output of previous ones (I use -sync yes to make sure they are run in order). Until now, I simply submitted the jobs using system, but I would like to achieve that the main script dies when a job in the sequence fails, instead of pointlessly going on. Since this occurs several times in my code, I used a subroutine to code it:

&qsub("qsub $qsub_options $subscript $script_args", "Some files are broken");
In the subroutine, I want to capture the exit code and possible message printed by SGE so I can potentially terminate the main script. I looked up the module IO::CaptureOutput and tried the following:
sub qsub { my ($cmd, $error_message) = @_; my @cmd = @{ $cmd }; my ($stdout,$stderr,$success,$exit_code) = capture_exec(@cmd); if (($exit_code > 0) || ($stderr)) { die "$error_message\n"; } }

This doesn't work, however. I get an error related to strict because of the @cmd array, but I don't understand why it has to be an array. Actually, I tried using a scalar first, but it didn't work either.

For reference, the relevant part of the SGE man page says: "If -sync y is used ... If all the job's tasks complete successfully, qsub's exit code will be ... 0 ... If any of the job's tasks fail ..., qsub will print out an error message ... and will have an exit code of 1".

Can somebody explain what's going on and help me fix it?


In reply to Capturing SGE exit code in Perl by Anonymous Monk

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.